<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sujay M</title>
    <description>The latest articles on DEV Community by Sujay M (@sujay_m_8c9c943744ecd9a29).</description>
    <link>https://dev.to/sujay_m_8c9c943744ecd9a29</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4272040%2Fdc49d7ba-6212-49ff-aa0b-d80be5fb896f.png</url>
      <title>DEV Community: Sujay M</title>
      <link>https://dev.to/sujay_m_8c9c943744ecd9a29</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sujay_m_8c9c943744ecd9a29"/>
    <language>en</language>
    <item>
      <title>How I Built a Zero-Upload PDF Compressor in Browser Web Workers (Without Breaking Selectable Text)</title>
      <dc:creator>Sujay M</dc:creator>
      <pubDate>Sun, 29 Nov 2026 09:55:17 +0000</pubDate>
      <link>https://dev.to/sujay_m_8c9c943744ecd9a29/how-i-built-a-zero-upload-pdf-compressor-in-browser-web-workers-without-breaking-selectable-text-35d6</link>
      <guid>https://dev.to/sujay_m_8c9c943744ecd9a29/how-i-built-a-zero-upload-pdf-compressor-in-browser-web-workers-without-breaking-selectable-text-35d6</guid>
      <description>&lt;p&gt;When job seekers or students need to shrink a resume or certificate under a strict &lt;strong&gt;100 KB&lt;/strong&gt; or &lt;strong&gt;200 KB&lt;/strong&gt; upload limit, most online PDF compressors do two frustrating things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They upload private documents (resumes, Aadhaar/ID cards, bank statements, transcripts) to remote servers.&lt;/li&gt;
&lt;li&gt;They blindly rasterize every page into low-DPI JPEGs—which destroys &lt;strong&gt;selectable text&lt;/strong&gt;, breaks &lt;strong&gt;clickable portfolio links&lt;/strong&gt;, and causes Applicant Tracking Systems (ATS) to read a blank page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While building &lt;strong&gt;&lt;a href="https://pdfblink.pages.dev/" rel="noopener noreferrer"&gt;PDFBlink&lt;/a&gt;&lt;/strong&gt;—a free static suite of 21 PDF tools hosted on Cloudflare Pages—I wanted a compression pipeline that runs &lt;strong&gt;100% inside the user's browser&lt;/strong&gt;, keeps selectable text intact whenever possible, and never crashes mobile tabs.&lt;/p&gt;

&lt;p&gt;Here is how the architecture works.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Zero-Upload Execution Inside Dedicated Web Workers
&lt;/h3&gt;

&lt;p&gt;PDFBlink is a static Next.js export (&lt;code&gt;output: "export"&lt;/code&gt;). There is no backend upload API at all—every PDF parse, compression pass, merge, split, and image conversion happens locally inside browser memory, which you can verify directly in Chrome DevTools → &lt;strong&gt;Network&lt;/strong&gt; (&lt;code&gt;0&lt;/code&gt; upload requests).&lt;/p&gt;

&lt;p&gt;To keep the UI responsive during heavy image decoding and rendering, compression runs inside a dedicated Web Worker (&lt;code&gt;compression.worker.ts&lt;/code&gt;) using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pdf-lib&lt;/code&gt;&lt;/strong&gt; for structural inspection, object-stream compression, metadata stripping, and PDF reassembly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Self-hosted Mozilla &lt;code&gt;PDF.js&lt;/code&gt; (&lt;code&gt;pdfjs-dist&lt;/code&gt;)&lt;/strong&gt; WASM, CMaps, and standard fonts served locally from &lt;code&gt;/pdfjs/&lt;/code&gt; and &lt;code&gt;/workers/&lt;/code&gt; (no external CDN dependencies at runtime).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;OffscreenCanvas&lt;/code&gt;&lt;/strong&gt; inside the worker for re-encoding image XObjects and rendering bounded page bitmaps when required.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. Two-Mode Compression: Quality-Preserving vs. Bounded Rasterization
&lt;/h3&gt;

&lt;p&gt;Instead of one destructive slider, &lt;a href="https://pdfblink.pages.dev/compress-pdf/" rel="noopener noreferrer"&gt;PDFBlink Compress PDF&lt;/a&gt; separates compression into two distinct modes (explained in detail in &lt;a href="https://pdfblink.pages.dev/blog/lossless-vs-lossy-pdf-compression/" rel="noopener noreferrer"&gt;Lossless vs. Lossy PDF Compression&lt;/a&gt;):&lt;/p&gt;

&lt;h4&gt;
  
  
  Mode A: Quality-Preserving (ATS-Safe)
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Structural &amp;amp; Metadata Cleanup:&lt;/strong&gt; Optionally deletes &lt;code&gt;/Info&lt;/code&gt; dictionary entries (&lt;code&gt;Title&lt;/code&gt;, &lt;code&gt;Author&lt;/code&gt;, &lt;code&gt;Creator&lt;/code&gt;, &lt;code&gt;Producer&lt;/code&gt;) and XMP &lt;code&gt;/Metadata&lt;/code&gt; streams while disabling automatic metadata regeneration on save, and writes compressed PDF object streams (&lt;code&gt;useObjectStreams: true&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Selective Image XObject Re-encoding:&lt;/strong&gt; Walks indirect PDF objects looking for eligible &lt;code&gt;/Subtype /Image&lt;/code&gt; streams (&lt;code&gt;DCTDecode&lt;/code&gt; JPEGs and uncompressed RGB/Grayscale bitmaps, skipping masked/alpha images and &lt;code&gt;N=4&lt;/code&gt; CMYK ICC profiles to prevent color corruption).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Byte-Budget Guard:&lt;/strong&gt; Only replaces an embedded image stream if the re-encoded JPEG is genuinely smaller (&lt;code&gt;&amp;lt; 96%&lt;/code&gt; of original bytes). Vector text, fonts, hyperlinks, forms, and bookmarks remain untouched.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In a live browser test on a 2-page &lt;code&gt;196 KB&lt;/code&gt; sample transcript with embedded graphics, Quality-Preserving mode reduced the file to &lt;strong&gt;&lt;code&gt;73 KB&lt;/code&gt; (62.7% smaller)&lt;/strong&gt; while retaining selectable text.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mode B: Bounded Rasterization (Strict KB Caps)
&lt;/h4&gt;

&lt;p&gt;If a user targets a strict cap like &lt;a href="https://pdfblink.pages.dev/compress-pdf-to-100kb/" rel="noopener noreferrer"&gt;Compress PDF to 100 KB&lt;/a&gt; or &lt;code&gt;200 KB&lt;/code&gt; on a heavy camera-scanned PDF where Quality-Preserving mode cannot reach the cap alone, PDFBlink—only when allowed—runs bounded rasterization iterations across resolution scale and JPEG quality until it meets the target or hits a readability floor (and warns clearly beforehand whenever rasterization will flatten selectable text, forms, or links, or invalidate digital signatures).&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Mobile Browser Guardrails &amp;amp; Honest Pre-Flight Inspection
&lt;/h3&gt;

&lt;p&gt;Browser PDF tools fail most often on smartphones when users drop a 60-page scan into an unguarded &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; loop. PDFBlink enforces explicit device-aware limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Desktop:&lt;/strong&gt; up to &lt;code&gt;100 MB&lt;/code&gt; per file, &lt;code&gt;150 MB&lt;/code&gt; batch, &lt;code&gt;250&lt;/code&gt; structural pages, &lt;code&gt;80&lt;/code&gt; rasterization pages, &lt;code&gt;4096 × 4096&lt;/code&gt; max canvas (&lt;code&gt;16.7M&lt;/code&gt; pixels), and &lt;code&gt;90s&lt;/code&gt; timeout with &lt;code&gt;AbortSignal&lt;/code&gt; cancellation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mobile / Low-RAM (&lt;code&gt;&amp;lt;= 4 GB&lt;/code&gt;):&lt;/strong&gt; up to &lt;code&gt;40 MB&lt;/code&gt; per file, &lt;code&gt;60 MB&lt;/code&gt; batch, &lt;code&gt;150&lt;/code&gt; structural pages, &lt;code&gt;40&lt;/code&gt; rasterization pages, and &lt;code&gt;2500 × 2500&lt;/code&gt; max canvas (&lt;code&gt;6.25M&lt;/code&gt; pixels).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before processing, a magic-byte and structure validator checks for spoofed extensions, encrypted PDFs (&lt;code&gt;/Encrypt&lt;/code&gt; dictionary, cleanly rejected rather than attempting password bypass), and digital signatures, AcroForms, hyperlinks, and bookmarks—surfacing upfront warnings before any bytes are changed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Try It &amp;amp; Inspect the Network Tab Yourself
&lt;/h3&gt;

&lt;p&gt;You can test the compression pipeline, &lt;a href="https://pdfblink.pages.dev/merge-pdf-without-login/" rel="noopener noreferrer"&gt;Merge PDF Without Login&lt;/a&gt;, &lt;a href="https://pdfblink.pages.dev/pdf-metadata-viewer/" rel="noopener noreferrer"&gt;PDF Metadata Viewer&lt;/a&gt;, or any of the 21 tools at &lt;strong&gt;&lt;a href="https://pdfblink.pages.dev/" rel="noopener noreferrer"&gt;https://pdfblink.pages.dev/&lt;/a&gt;&lt;/strong&gt;—and open your browser's Network tab while processing to verify zero uploads leave your device.&lt;/p&gt;

&lt;p&gt;If you run into tricky real-world PDFs (CMYK scans, weird XObjects, or strict portal limits), I'd love to hear about them!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>performance</category>
      <category>privacy</category>
      <category>tools</category>
    </item>
  </channel>
</rss>
