Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a responsive PDF, calculate the page’s display scale from the viewer’s available width, then render again whenever that width changes. With PDF.js, keep the canvas’s high-resolution backing store separate from its CSS size so the page stays sharp on HiDPI screens. A DOCX file does not reflow in a browser on its own: convert it to HTML and make the exported content responsive, or keep it paginated in a document viewer.

Choose the right approach: PDF scaling or DOCX reflow

PDF and DOCX need different solutions. A PDF already has fixed page dimensions; a viewer can scale each page to fit a container without changing its pagination. A DOCX is a word-processing format, not a browser layout. To make its content adapt continuously to screen width, convert or export it to HTML and apply responsive CSS.

Need Practical approach Trade-off
Keep PDF pagination and fit each page to the viewer PDF.js width-based rendering, or the stock viewer’s page-width zoom Text is scaled as part of a page; it does not reflow like a web article.
Show DOCX content that reflows on phones Convert or export to HTML, then style the HTML and its assets responsively Conversion may change layout details; inspect the result.
Preserve exact Word page breaks Offer the DOCX for download or use a paginated document viewer Fixed pagination is less flexible on narrow screens.

The implementation below uses PDF.js for a custom fit-to-width viewer. PDF.js separates its core parser, display API and viewer layer; Mozilla describes its viewer as a starting point for a custom viewer, which should be re-skinned or built upon rather than treated as a drop-in final design. See the PDF.js setup guidance.

Make a PDF canvas fit its container with PDF.js

The key calculation is scale = availableWidth / pageWidthAtScale1. PDF.js viewports express page dimensions in pixels at 72 DPI and include the page’s initial rotation. Measure the actual inner width available to the page, create a scale-1 viewport, derive the scale, and then render a new viewport at that scale. The official PDF.js example demonstrates the width-derived formula.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0

Runnable single-page example

This example assumes that PDF.js and its worker are installed and served by your application. Replace the import paths with the paths for your installed package or hosted build. Serve the page over HTTP or HTTPS, not by opening it with file://: PDF.js does not enable its worker for file URLs. The official getting-started guide lists the current stable prebuilt version as 6.3.289 when accessed in 2026; check that guide for the version and setup applicable to your project.

<div id="pdf-viewer"><canvas id="pdf-canvas"></canvas></div>
<script type="module">
  import * as pdfjsLib from "/pdfjs/build/pdf.mjs";

  pdfjsLib.GlobalWorkerOptions.workerSrc = "/pdfjs/build/pdf.worker.mjs";

  const container = document.querySelector("#pdf-viewer");
  const canvas = document.querySelector("#pdf-canvas");
  const context = canvas.getContext("2d");
  const pdfUrl = "/documents/example.pdf";

  const loadingTask = pdfjsLib.getDocument(pdfUrl);
  const pdf = await loadingTask.promise;
  const page = await pdf.getPage(1);
  let renderTask;

  async function renderPage() {
    const availableWidth = container.clientWidth;
    if (!availableWidth) return;

    if (renderTask) {
      renderTask.cancel();
      try { await renderTask.promise; } catch (error) {
        if (error.name !== "RenderingCancelledException") throw error;
      }
    }

    const baseViewport = page.getViewport({ scale: 1 });
    const scale = availableWidth / baseViewport.width;
    const viewport = page.getViewport({ scale });
    const outputScale = window.devicePixelRatio || 1;

    canvas.width = Math.floor(viewport.width * outputScale);
    canvas.height = Math.floor(viewport.height * outputScale);
    canvas.style.width = `${viewport.width}px`;
    canvas.style.height = `${viewport.height}px`;

    renderTask = page.render({
      canvasContext: context,
      viewport,
      transform: outputScale !== 1
        ? [outputScale, 0, 0, outputScale, 0, 0]
        : null,
    });

    await renderTask.promise;
  }

  const resizeObserver = new ResizeObserver(() => {
    renderPage().catch(console.error);
  });
  resizeObserver.observe(container);
  await renderPage();
</script>

<style>
  #pdf-viewer { width: 100%; overflow: auto; }
  #pdf-canvas { display: block; max-width: 100%; margin: 0 auto; }
</style>

The separate dimensions are essential. canvas.width and canvas.height set the bitmap’s backing-store resolution; the style dimensions set its on-screen CSS size. Multiplying the backing-store size by devicePixelRatio and passing the same scale as the render transform provides extra pixels for high-density displays, while keeping the displayed page at the calculated CSS width.

Container sizing and large screens

Measure the viewer container rather than the browser window. If the viewer has padding, measure its content area or subtract the padding explicitly. A sidebar, toolbar or split pane can make the usable page width much smaller than window.innerWidth. On very large displays, consider clamping the scale to avoid enlarging pages beyond a useful reading size; choose that maximum based on your interface rather than treating it as a PDF.js requirement.

Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

The sample fits one page at a time. To display a multipage PDF, retrieve each page and render it into its own canvas using the same width calculation. Do not create every canvas at high resolution immediately: render pages near the viewport and release or reuse canvases for distant pages. Mozilla’s PDF.js FAQ says the demo viewer creates, renders and holds canvases only for visible pages to reduce memory use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the stock PDF.js viewer when you do not need a custom renderer

The stock viewer supports zoom modes including page-width, page-height, page-fit and auto. For example, the viewer URL can use #zoom=page-width. When opening a remote PDF through the viewer, pass the document in the file query parameter and URL-encode its URL, for example:

https://your-site.example/pdfjs/web/viewer.html?file=%2Fdocuments%2Fexample.pdf#zoom=page-width

Use your deployed viewer path in place of the example host and path. Follow the PDF.js getting-started documentation for deployment details. A custom canvas is appropriate when you need to control layout, behavior or styling; the stock viewer is simpler when its controls and page-width mode meet your needs.

Rank #3
Sale
Epson Workforce ES-400 II High-Speed Color Duplex Desktop Document Scanner
  • FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
  • INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
  • SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
  • EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
  • SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning

Make DOCX content responsive in a web page

A DOCX should be converted or saved as web content before you apply browser-width rules. Microsoft’s Word web-settings API documents export controls including relyOnCSS (whether CSS is used for font formatting), pixelsPerInch (the density used for graphics and table cells), and screenSize (the intended minimum browser viewport). These settings can affect exported content, but they do not establish a universal conversion engine or guarantee that every Word layout will match in HTML. See Microsoft’s Word web-settings documentation.

Export, then add responsive CSS

Once your chosen Word workflow has produced HTML and assets, constrain images and manage wide tables so they cannot force the whole page wider than the viewport:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.document-content {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.document-content img,
.document-content video {
  max-width: 100%;
  height: auto;
}

.document-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.document-table-wrap table {
  border-collapse: collapse;
}

Wrap wide tables in an element such as .document-table-wrap so the table can scroll horizontally without widening the entire document. Apply the same principle to other content that has an intrinsic width wider than a phone. Inspect headings, lists, links, tables and image alternative text after conversion: the output can vary with document features, so do not assume that a visually similar page is structurally accessible.

Rank #4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images

If exact Word pagination matters more than fluid reflow, keep the DOCX as a download or use a paginated viewer. If reflow and accessibility matter more, HTML is usually the more suitable display target, but it requires checking the converted structure and layout.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep rendering fast and avoid stale pages

Render on resize without overlapping work

A ResizeObserver lets the viewer respond when its container changes size for reasons other than a window resize, such as a sidebar opening. Each new render should cancel or wait for the previous one. Otherwise, a slower render started at the old width can finish last and overwrite the correctly sized page. The example cancels an active PDF.js render task and ignores the expected cancellation exception before starting the next render.

Limit canvas memory

High-DPI canvases use substantially more memory because both bitmap dimensions grow with the output scale. Mozilla’s PDF.js FAQ illustrates the scale of the cost: a letter-size page at 96 DPI is 816 × 1056 pixels and takes about 3.5 MB per canvas, or about 14 MB at 2× HiDPI, before render-time overhead. These are the FAQ’s illustrative figures, not a measurement of every browser or document. Virtualize pages and render only those close to view instead of retaining a full high-resolution canvas for every page.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
ScanSnap iX2500 Wireless or USB High-Speed Document Scanner, Black
  • OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
  • CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
  • STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
  • PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
  • AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss

Use range loading when the server permits it

PDF.js can request portions of a PDF for visible content when the server supports HTTP Range Requests and the browser is allowed to use them. Cross-origin delivery may require CORS configuration that permits the relevant requests and exposes needed response headers. Test with your actual server and documents; range loading is not guaranteed merely by using PDF.js.

Troubleshoot width, loading and rendering problems

  • The page stays too wide. Check that the measured width is the viewer’s usable content width, not the viewport width. Account for padding and sidebars, and make sure the CSS width is set from the scaled viewport rather than the unscaled page.
  • The page looks blurry on a Retina or HiDPI screen. Confirm that the canvas backing dimensions use devicePixelRatio and that the render call receives the corresponding output transform. Do not enlarge the CSS width to compensate; CSS dimensions and bitmap dimensions serve different purposes.
  • The page goes blank or changes to the wrong size after resizing. Serialize or cancel concurrent render tasks. Observe the container, not just window resize events, and avoid rendering while its measured width is zero (for example, while a hidden tab is hidden).
  • The PDF or worker fails when opened from disk. Serve the application and PDF over HTTP or HTTPS. PDF.js’s worker is not enabled for file:// URLs; configure the worker path to match the deployed build.
  • A remote PDF fails to load in the stock viewer. URL-encode the PDF URL in the viewer’s file parameter, then check same-origin access, CORS policy or a server-side proxy. A syntactically correct viewer URL cannot bypass the PDF host’s access controls.
  • A remote document loads slowly or only after downloading fully. Verify that the server supports range requests and that browser cross-origin rules permit the necessary access. Check the network response headers for the real PDF rather than assuming partial loading is active.
  • A DOCX table creates horizontal page scrolling. Put the table in an overflow container, and inspect other elements with fixed widths. Constraining images alone will not fix a wide table.
  • A scanned PDF has no selectable text. Scaling the canvas changes its displayed size; it does not add semantic text or OCR. If text selection or reflow is needed, the document requires a text layer or OCR workflow, and its results should be checked against the source.

Or skip the browser setup

If the goal is to capture a web page at a chosen viewport rather than embed and render a document inside your own application, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG or WebP screenshot, or a PDF. For example, save a page capture as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for API options. Cookie banners are accepted and more than 60 known consent platforms, newsletter popups and chat widgets are removed before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits cost nothing, and the response includes X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info and capture_pdf for AI agents. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month, with no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does scaling a PDF canvas make its text responsive or selectable?

No. Canvas scaling changes the rendered page size; it does not reflow the page’s text or create semantic text. Use a text layer or OCR workflow if a scanned document needs selectable text.

Should I use PDF.js or convert a DOCX to HTML?

Use PDF.js when the source is a PDF and you want to preserve page pagination while fitting pages to a viewer. Convert DOCX to HTML when responsive reflow is the priority; choose a paginated viewer or downloadable DOCX when Word page breaks matter.

Quick Recap

Bestseller No. 4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.