惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
Cyberwarzone
Cyberwarzone
博客园 - Franky
V
V2EX
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
Martin Fowler
Martin Fowler
The Cloudflare Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
D
Docker
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Announcements
Recent Announcements
L
LINUX DO - 热门话题
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
O
OpenAI News
雷峰网
雷峰网
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Help Net Security
Help Net Security
F
Full Disclosure
Engineering at Meta
Engineering at Meta
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
AI
AI
Spread Privacy
Spread Privacy

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK How Subject scaled 5× with Nutrient’s PDF SDK without rebuilding its document layer I replaced our sales training with an AI coach that runs in Slack — here’s what broke Redirecting to: https://securitybuzz.com/cybersecurity-news/why-enterprise-permissions-are-ais-most-dangerous-inheritance/ Nutrient .NET SDK vs. iText Core: Complete comparison for .NET developers DocuVieware: Support’s most frequently asked setup questions Introducing Nutrient Workflow How to convert PDF to Word in C# (.NET) When email and spreadsheets stop working: Work order approval workflows for field teams on the move Compliance with confidence: Why document-centric automation is the foundation of your mission Nutrient expands AI Assistant, automating multistep document workflows inside any application What is document generation? A developer’s guide to PDF generation Document Converter data flow and how real-time watermarks skip the queue PDF/UA compliance guide: Requirements, standards, and best practices Computers still can’t understand you How Athena Intelligence built AI agents for regulated enterprises with Nutrient’s document infrastructure How to convert HTML to PDF (2026): 4 methods from browser print to SDK How to build a document extraction pipeline with Nutrient Vision API OCR vs. intelligent document processing: Choosing the right document extraction engine Beyond OCR: How document intelligence eliminates manual processing in regulated industries Nutrient vs. IronPDF: Complete comparison for .NET developers Nutrient vs. Aspose.PDF: Complete comparison for .NET developers Redirecting to: https://fortune.com/2026/02/19/openclaw-who-is-peter-steinberger-openai-sam-altman-anthropic-moltbook/ Lufthansa Systems uses Nutrient to deliver reliable, scalable PDF rendering for pilots worldwide Nutrient vs. Syncfusion: Complete comparison for .NET developers React’s useTransition: The hook you’re probably using wrong First City Monument Bank streamlines banking processes with Nutrient Workflow Redirecting to: https://www.sdcexec.com/warehousing/automation/article/22957364/nutrient-workflow-automation-the-missing-link-in-supply-chain-efficiency The complete guide to digital signatures: PAdES, CAdES, and XAdES explained Nutrient Python SDK: Production-grade document processing for Python Introducing agentic document editing for web applications with AI Assistant Nutrient vs. QuestPDF: Complete comparison for .NET developers How we fixed the GdPicture license expiration (and what to do if you’re affected) Red team security testing with agentic AI The future of healthcare document automation Best healthcare workflow software compared Nutrient SDK product updates for Q4 2025 How Harvey scaled legal document workflows 50 percent MoM without rebuilding infrastructure HIPAA-compliant document management in hospitals How we optimized rendering performance while handling thousands of annotations in React — Part 2 Automated PII removal with Nutrient API Redirecting to: https://www.devopsdigest.com/2026-low-code-no-code-predictions Redirecting to: https://www.kmworld.com/Articles/Editorial/ViewPoints/Leaders-predict-AI-to-continue-permeating-all-aspects-of-KM-in-2026-172594.aspx What are deep agents and how do they solve complex problems? Whipping up document magic: Your easy-bake recipe for Vue and Nutrient Web SDK 🧁 What I’ve learned about product iteration planning while building SDKs Passwordless document signing: Three-layer security guide New zip folder functionality streamlines file management in Document Automation Server The keyboard shortcuts playbook: Taking control of keyboard events in Nutrient Web SDK From experienced engineer to AI beginner: My unexpected journey AI-assisted manual testing: Handling Safari’s PDF rendering and UI quirks How to keep a 20-year-old SDK up to date How we optimized rendering performance while handling thousands of annotations in React — Part 1 Nutrient announces new executive hires to accelerate next phase of growth High performance UI using web workers Automate document conversion at scale with Python and Nutrient DCS From curiosity to PLG (and AI): My journey to understanding product-led growth Prost to progress: One year as Nutrient Pigeon usage at Nutrient: Bridging native SDKs to Flutter Modernizing CI build servers: How to migrate from Chef to Ansible Unix man pages: AI-friendly documentation since 1971 Consistent hashing for even load distribution Best AI redaction APIs: Complete comparison guide for 2025 Why AI document redaction matters for modern security From coding to coordinating: How AI transformed my workflow What is intelligent document processing (IDP)? A complete guide Enterprise PDF SDKs: Best PSPDFKit (now Nutrient) alternatives Nutrient SDK product updates for Q3 2025 GdPicture support best practices Redacting sensitive data with Nutrient AI redaction API How AI is transforming the customer experience at Nutrient: From instant answers to intelligent support
How to add PDF page navigation, zoom, and rotation controls with PDF.js
Austin Nguyen · 2026-06-16 · via Inside Nutrient

Table of contents

    Build a complete PDF viewer toolbar with page navigation, zoom controls, and rotation using the PDF.js PDFViewer API and EventBus. This tutorial includes a ready-to-use React toolbar component.

    How to add PDF page navigation, zoom, and rotation controls with PDF.js

    TL;DR

    Build a PDF.js toolbar with navigation, zoom, and rotation by operating on the PDFViewer instance and subscribing to EventBus events:

    • Page navigationviewer.currentPageNumber, previousPage(), nextPage(), listen for pagechanging
    • Zoom — Assign string values ("auto", "page-width", "1.5") to viewer.currentScaleValue, listen for scalechanging
    • Rotation — Increment viewer.pagesRotation in 90-degree increments, listen for rotationchanging
    • Layout refresh — Call viewer.update() on panel resizes
    • Precise scroll-to-position — Use PDFLinkService.goToDestination with the XYZ destination type

    If you’d rather skip the wiring, Nutrient Web SDK ships a built-in toolbar and a typed ViewState API.

    Building a toolbar for your PDF viewer means wiring up controls for page navigation, zoom, and rotation. All three operate through the PDFViewer instance and the EventBus.

    The PDFViewer instance tracks the current page and exposes methods to move between pages, while the EventBus reports page changes back to your UI.

    Reading current page

    const currentPage = viewer.currentPageNumber; // 1-indexed.

    const totalPages = pdfDocument.numPages;

    Changing pages

    // Go to a specific page.

    viewer.currentPageNumber = 5;

    // Previous/Next.

    viewer.previousPage();

    viewer.nextPage();

    Listening for page changes

    eventBus.on("pagechanging", (evt) => {

    setCurrentPage(evt.pageNumber);

    });

    Use PDFLinkService.goToDestination to scroll to an exact position on a page:

    linkService.goToDestination([

    pageIndex, // 0-indexed page number.

    { name: "XYZ" }, // destination type.

    scrollLeft, // x position (PDF coordinates), or null for current.

    scrollTop, // y position (PDF coordinates), or null for current.

    null, // zoom level, or null for current.

    ]);

    This is the same mechanism PDF internal links use to scroll to a target location.

    React page navigation component

    The component below assumes a PDFContext that exposes viewer, eventBus, and pdfDocument as references (typically populated when the PDF.js PDFViewer is initialized in a parent component).

    import { useContext, useEffect, useState } from "react";

    import { PDFContext } from "./PDFContext";

    function PageToolbar() {

    const { viewer, eventBus, pdfDocument } = useContext(PDFContext);

    const [currentPage, setCurrentPage] = useState(1);

    const [totalPages, setTotalPages] = useState(0);

    useEffect(() => {

    if (pdfDocument.current) {

    setTotalPages(pdfDocument.current.numPages);

    }

    }, [pdfDocument]);

    useEffect(() => {

    const handler = (evt) => setCurrentPage(evt.pageNumber);

    eventBus.current?.on("pagechanging", handler);

    return () => eventBus.current?.off("pagechanging", handler);

    }, [eventBus]);

    return (

    <div>

    <button

    onClick={() => viewer.current?.previousPage()}

    disabled={currentPage <= 1}

    >

    Previous

    </button>

    <input

    type="number"

    value={currentPage}

    min={1}

    max={totalPages}

    onChange={(e) => {

    const page = parseInt(e.target.value, 10);

    if (page >= 1 && page <= totalPages) {

    viewer.current.currentPageNumber = page;

    }

    }}

    />

    <span>of {totalPages}</span>

    <button

    onClick={() => viewer.current?.nextPage()}

    disabled={currentPage >= totalPages}

    >

    Next

    </button>

    </div>

    );

    }

    Zoom/scale

    Zoom is controlled through viewer.currentScaleValue, which accepts both preset keywords and numeric values, and the EventBus emits a scalechanging event whenever the scale updates.

    Setting scale

    // Preset values (strings).

    viewer.currentScaleValue = "auto"; // Fit to container.

    viewer.currentScaleValue = "page-width"; // Fit width.

    viewer.currentScaleValue = "page-fit"; // Fit entire page.

    // Numeric values (as string).

    viewer.currentScaleValue = "1.5"; // 150 percent zoom.

    viewer.currentScaleValue = "0.75"; // 75 percent zoom.

    Zoom in/out

    function zoomIn(viewer) {

    const current = parseFloat(viewer.currentScaleValue) || 1;

    viewer.currentScaleValue = String(Math.min(current + 0.25, 5));

    }

    function zoomOut(viewer) {

    const current = parseFloat(viewer.currentScaleValue) || 1;

    viewer.currentScaleValue = String(Math.max(current - 0.25, 0.25));

    }

    Listening for scale changes

    eventBus.on("scalechanging", (evt) => {

    setScale(evt.scale); // numeric value.

    setPreset(evt.presetValue); // "auto", "page-width", etc.

    });

    Rotation

    The viewer.pagesRotation property holds the current rotation, which you change in 90-degree increments. Each change adds to the previous value, and the EventBus fires a rotationchanging event whenever the rotation updates.

    Rotating pages

    // Rotate 90 degrees clockwise.

    viewer.pagesRotation += 90;

    // Rotate 90 degrees counterclockwise.

    viewer.pagesRotation -= 90;

    pagesRotation is cumulative. Values are in degrees (0, 90, 180, 270).

    Listening for rotation changes

    eventBus.on("rotationchanging", (evt) => {

    setRotation(evt.pagesRotation);

    });

    Force refresh on layout changes

    If your PDF viewer is in a resizable panel (sidebar toggle, split view), the pages may not reflow automatically. Force a refresh by calling viewer.update():

    function refreshViewer() {

    viewer.update();

    }

    // Call on panel resize, sidebar toggle, etc.

    window.addEventListener("resize", refreshViewer);

    // Or use a custom event.

    window.addEventListener("refresh-pdf-viewer", refreshViewer);

    import { useContext, useEffect, useState } from "react";

    import { PDFContext } from "./PDFContext";

    function PDFToolbar() {

    const { viewer, eventBus, pdfDocument } = useContext(PDFContext);

    const [page, setPage] = useState(1);

    const [total, setTotal] = useState(0);

    useEffect(() => {

    setTotal(pdfDocument.current?.numPages || 0);

    const h = (e) => setPage(e.pageNumber);

    eventBus.current?.on("pagechanging", h);

    return () => eventBus.current?.off("pagechanging", h);

    }, [eventBus, pdfDocument]);

    return (

    <div className="pdf-toolbar">

    {/* Page Navigation */}

    <button onClick={() => viewer.current?.previousPage()}>Prev</button>

    <span>{page} / {total}</span>

    <button onClick={() => viewer.current?.nextPage()}>Next</button>

    {/* Zoom */}

    <button onClick={() => viewer.current && zoomOut(viewer.current)}>-</button>

    <button onClick={() => {

    if (viewer.current) viewer.current.currentScaleValue = "page-width";

    }}>Fit Width</button>

    <button onClick={() => viewer.current && zoomIn(viewer.current)}>+</button>

    {/* Rotation */}

    <button onClick={() => {

    if (viewer.current) viewer.current.pagesRotation -= 90;

    }}>Rotate Left</button>

    <button onClick={() => {

    if (viewer.current) viewer.current.pagesRotation += 90;

    }}>Rotate Right</button>

    </div>

    );

    }

    Key points

    • Page numbers are 1-indexed in viewer.currentPageNumber but 0-indexed in goToDestination
    • Scale values are strings — even numeric values like "1.5"
    • Rotation accumulates in degrees on viewer.pagesRotation
    • Always listen to EventBus events to keep your UI in sync with the viewer state
    • Call viewer.update() to force a layout refresh after panel resizes
    • goToDestination with "XYZ" type gives you precise scroll-to-position control

    FAQ

    currentPageNumber is the user-facing page number (matches “Page 1 of 10” in the UI). goToDestination takes the array form from the PDF specification, where the first element is a zero-based page index. The two indexing conventions are intentional but easy to mix up.

    viewer.currentScaleValue accepts both preset keywords ("auto", "page-width", "page-fit") and numeric zoom levels ("1.5" for 150 percent) as strings. Using a single string type lets PDF.js distinguish “fit-to-width” from a hardcoded zoom. Always pass strings — viewer.currentScaleValue = 1.5 silently fails.

    Call viewer.update(). This remeasures the container and reflows the pages. Common triggers: sidebar toggles, split-pane resizes, fullscreen transitions, and dynamic CSS changes that affect the container’s dimensions.

    You need pdfjs-dist/web/pdf_viewer.css for the text layer, annotation layer, and page layout. The toolbar is your own React component, so it uses your own styles. Without the PDF.js CSS, pages render, but text selection and annotations break.

    Nutrient ships a built-in toolbar with navigation, zoom, rotation, and search controls, plus a typed ViewState API for programmatic control. There’s no EventBus, no string-typed scale values, and no manual layout refresh. See the migration guide for switching from PDF.js.

    How Nutrient Web SDK handles this

    Instead of wiring up EventBus listeners, parsing string-typed scale values, and manually refreshing layouts, Nutrient’s ViewState API handles navigation, zoom, and rotation declaratively:

    // Page navigation.

    instance.setViewState((v) => v.set("currentPageIndex", 4));

    // Zoom.

    instance.setViewState((v) => v.set("zoom", "FIT_WIDTH"));

    // Rotation.

    instance.setViewState((v) =>

    v.set("pagesRotation", (v.pagesRotation + 90) % 360),

    );

    The built-in toolbar ships with navigation controls, and ViewState keeps the toolbar, thumbnails, and scroll position in sync automatically.


    See Nutrient Web SDK for an alternative to PDF.js, or follow the migration guide to switch. Talk to Sales about your requirements.

    Explore related topics

    Try for free Ready to get started?

    Related SDK articles

    Explore more