DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

How to Build a Browser-Only PDF Compression Workflow with PDF.js

A browser-only PDF size-reduction pipeline renders pages with PDF.js, encodes them as images, and rebuilds the file with a PDF-writing library. Size savings and fidelity depend on the document and settings.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can build a browser-only PDF size-reduction workflow by rendering each source page with PDF.js, encoding the rendered pages as images, and assembling those images into a new PDF with a separate PDF-writing library such as pdf-lib. OffscreenCanvas and Web Workers can help with rendering or image processing, but they do not make PDF.js a PDF compressor—and rasterizing a document does not guarantee a smaller file.

What this workflow does—and what it does not

PDF.js is a parsing and rendering component. It loads a PDF, exposes document and page objects, and can render pages to a canvas. It is not, in the documented workflow described here, the step that writes a compressed replacement PDF.

As an Amazon Associate I earn from qualifying purchases.

The output step is reconstruction: encode each rendered page as an image, create a new PDF, and place one image on each new page. pdf-lib documents creating PDF documents, embedding JPEG or PNG image bytes, adding pages, and saving in a browser context. The resulting pages are image-based representations of the originals, not the original PDF objects with their data selectively optimized.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

This can reduce size for some scan-heavy or image-heavy files, depending on the source and chosen resolution and image encoding. It can also make a file larger. It generally sacrifices the source document’s text and vector structure, and may not preserve links, forms, or other interactive features in the same way. Treat it as a trade-off, not a universal “compress” button.

#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

How the pieces fit together

Component Role in the workflow Important limit
PDF.js Loads the selected PDF, retrieves pages, and renders them using a viewport and canvas context. It supplies parsing and rendering, not the reconstructed output PDF.
OffscreenCanvas Can assist image conversion or rendering work where supported. It is a canvas API, not a PDF-writing format or compression engine.
Web Worker PDF.js distributions include a separate core worker; worker-thread rendering is an optional capability in the draft API documentation. A worker’s presence does not prove all rendering occurs off the UI thread. Rendering can fall back to the main thread.
PDF output library Embeds encoded page images into newly created PDF pages and saves the result. Embedding raster images does not restore the source’s text, vectors, or interactive structure.

Build the page-by-page pipeline

  1. Accept a local file. Let the user choose a PDF and read its bytes in the browser. Passing a locally selected file avoids the cross-origin fetch dependency that applies when loading a PDF from another website.
  2. Load and inspect with PDF.js. Use the installed PDF.js display library to load the bytes and retrieve the document. Its API is asynchronous; plan for loading and page operations to complete asynchronously rather than blocking the interface.
  3. Choose a rendering scale. For each page, create a viewport at the selected scale. Set the canvas dimensions from that viewport, accounting for the desired output scale, and render the page using the canvas context and viewport. Higher dimensions preserve more fine detail but require more memory and can produce larger encoded images.
  4. Encode the rendered page. Convert the canvas output to an image format and quality chosen by the implementation. JPEG is a practical option when lossy image encoding is acceptable; PNG is also supported by pdf-lib but has different size and fidelity trade-offs. Do not promise a particular quality level or byte reduction without testing the actual file and settings.
  5. Create and save a replacement PDF. Use a PDF-writing library to create a document, add a page for each rendered source page, embed that page’s image, and save the output in the browser. Preserve page proportions when sizing the image on the output page so the reconstructed page is not stretched.

Keep the PDF.js display library and its worker assets on the same version. PDF.js warns that mismatched versions are not guaranteed to work and can produce an API/worker version error. Bundle or serve the worker through the deployment setup for the pinned version; PDF.js documentation says its worker is not enabled for file:// URLs, so test through the local or production server path you intend to use.

Use OffscreenCanvas and workers without assuming they solve everything

OffscreenCanvas is best understood as an optional rendering or image-conversion aid. PDF.js documentation describes worker OffscreenCanvas support as primarily intended to improve image conversion and rendering performance, and documents a canvas-area threshold used to decide when an image is resized through OffscreenCanvas. That does not make OffscreenCanvas responsible for writing the output PDF.

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)

There are two separate questions when using workers: whether PDF.js’s core worker is configured, and whether page rendering itself runs in a worker thread. The draft API documentation describes optional rendering in a worker thread that requires GlobalWorkerOptions.rendererSrc. If that renderer worker is absent or fails, rendering falls back to the main thread; a custom ownerDocument also disables worker rendering. Because this API documentation is explicitly a draft and may change, confirm the configuration against the PDF.js version you pin.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check worker startup in the deployed build rather than inferring it from a successful local render.
  • Keep a fallback path for main-thread rendering, and present progress or cancellation controls if large documents could keep the interface busy.
  • Test the exact production asset paths and browser support for the versions you ship.

Control memory by rendering incrementally

Canvas memory can become substantial before image encoding or PDF assembly is considered. Mozilla PDF.js’s FAQ estimates that one letter-size page rendered at 816 × 1056 pixels, with 4 bytes per pixel at 96 DPI, occupies about 3,446,784 bytes—approximately 3.5 MB. The same FAQ estimates about 14 MB per page at device pixel ratio 2. These are illustrative canvas-memory estimates, not measurements of a compressor.

Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer

At those settings, a 100-page document can require roughly 3.5 MB per page’s canvas memory at 96 DPI, or about 14 MB per page at device pixel ratio 2, before accounting for other work. Avoid keeping every full-size canvas alive at once: render, encode, add the image to the output document, then release or reuse canvas resources as appropriate. This is an engineering precaution, not a measured performance result for a particular implementation.

Offer settings that expose the real trade-off

Give users control over the factors that determine output quality and size instead of presenting an unexplained compression percentage. A useful interface can include:

Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 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. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
  • Resolution or scale: lower settings reduce the pixels available for fine print and detail; higher settings use more memory and may create larger images.
  • Image format and quality: explain that lossy encoding can reduce image detail, while other formats may produce larger output depending on page content.
  • Output comparison: show the source and generated file sizes after processing, rather than predicting savings in advance.
  • Feature warning: tell users before conversion that output pages are rasterized and may not retain selectable/searchable text, links, forms, vectors, or document structure as in the source.

There is no source-published universal compression ratio for this pipeline. Report measured results only for named test files and declared settings; do not generalize a result from one PDF to all documents.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the result before offering it as a replacement

Evaluate representative documents against the original using the same settings. A smaller file is not automatically a better result if text becomes hard to read or important document behavior disappears.

Best Value
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
  • Compare output size with source size.
  • Inspect small text, fine lines, diagrams, and photographs at normal viewing size and when zoomed.
  • Check whether searchable text, links, forms, and vectors are still present if users need them.
  • Record the chosen output resolution and image encoding quality alongside measured results.
  • Observe processing time and peak memory on the page counts and devices you intend to support.
  • Verify worker availability and fallback behavior in the deployed build, including the server setup used to serve the PDF.js assets.

Handle remote PDFs separately

If users provide a URL instead of selecting a local file, the browser’s normal cross-origin rules apply. The remote server must permit the browser request through suitable CORS behavior, or the application needs an appropriate proxy. A proxy changes the architecture and moves some handling outside the browser; it should not be described as a wholly browser-only file flow.

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.