<?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: yue yuan</title>
    <description>The latest articles on DEV Community by yue yuan (@yue_yuan_6258252bfa28eea2).</description>
    <link>https://dev.to/yue_yuan_6258252bfa28eea2</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%2F4246907%2F0c285b89-dd5d-447e-87d9-9b8e6841ab74.png</url>
      <title>DEV Community: yue yuan</title>
      <link>https://dev.to/yue_yuan_6258252bfa28eea2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yue_yuan_6258252bfa28eea2"/>
    <language>en</language>
    <item>
      <title>How I built offline PDF processing with pdf-lib and pdf.js in the browser</title>
      <dc:creator>yue yuan</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:27:10 +0000</pubDate>
      <link>https://dev.to/yue_yuan_6258252bfa28eea2/how-i-built-offline-pdf-processing-with-pdf-lib-and-pdfjs-in-the-browser-4127</link>
      <guid>https://dev.to/yue_yuan_6258252bfa28eea2/how-i-built-offline-pdf-processing-with-pdf-lib-and-pdfjs-in-the-browser-4127</guid>
      <description>&lt;p&gt;Every "free online PDF tool" does the same thing: you drag a file into the page, and that file is uploaded to a server you'll never see, in a region you can't name, for a retention period nobody specifies.&lt;/p&gt;

&lt;p&gt;I wanted a PDF toolbox that never uploads anything. Not "we delete it after an hour" — never sends it at all. That meant all parsing, modification and serialization had to happen inside the browser tab.&lt;/p&gt;

&lt;p&gt;This is what that architecture looks like, and where it gets painful.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint that shapes everything
&lt;/h2&gt;

&lt;p&gt;Once you decide the file can't leave the device, a few things become impossible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No server-side Ghostscript for compression&lt;/li&gt;
&lt;li&gt;No server-side qpdf for encryption&lt;/li&gt;
&lt;li&gt;No "process in the background and email you the result"&lt;/li&gt;
&lt;li&gt;No file size limit that only exists because of your server's disk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything has to run in a single tab, with the memory a mobile browser is willing to give you. That constraint dictates the entire library choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two libraries, two very different jobs
&lt;/h2&gt;

&lt;p&gt;The split that ended up working:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pdf-lib&lt;/strong&gt; — writing. Merge, split, rotate, delete pages, watermark, encrypt. It gives you a mutable document model and serializes it back to bytes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pdf.js&lt;/strong&gt; — reading. Rendering thumbnails and page previews so users can pick pages before operating on them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both are vendored and inlined into the HTML. No CDN, no dynamic import. The page works from a cold cache with the network off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting pdf.js to run without a bundler
&lt;/h2&gt;

&lt;p&gt;pdf.js needs its worker. The usual failure is a cross-origin worker URL, which browsers refuse to construct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// fails in most browsers when the script is served from another origin&lt;/span&gt;
&lt;span class="n"&gt;pdfjsLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GlobalWorkerOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;workerSrc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://cdn.example.com/pdf.worker.min.js'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix that works everywhere, including file://-ish and offline scenarios, is to build the worker from a blob:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pdfjsWorkerSource&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/javascript'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pdfjsLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GlobalWorkerOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;workerSrc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pdfjsWorkerSource&lt;/code&gt; is the worker bundle as a string, inlined at build time. Costs you about 1MB of HTML, buys you zero network requests and no CORS surprises.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge, split, rotate: the easy 10%
&lt;/h2&gt;

&lt;p&gt;pdf-lib's document model is genuinely pleasant here. Merging is copy-pages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mergePdfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;PDFLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copyPages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPageIndices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Uint8Array&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Split and rotate are variations on the same theme. If your tool only did these, you could ship in an afternoon.&lt;/p&gt;

&lt;p&gt;The interesting problems are compression and encryption.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compression: pdf-lib does less than you think
&lt;/h2&gt;

&lt;p&gt;Here's the part that surprises people. &lt;code&gt;pdf-lib&lt;/code&gt; &lt;strong&gt;cannot re-encode embedded images&lt;/strong&gt;. It has no JPEG/JPEG2000 decode pipeline, no downsampler. When you call &lt;code&gt;save()&lt;/code&gt;, it applies &lt;code&gt;FlateDecode&lt;/code&gt; to content streams and leaves image streams alone.&lt;/p&gt;

&lt;p&gt;So "compress PDF in the browser" really means: strip redundancy from the streams you &lt;em&gt;can&lt;/em&gt; touch, and accept that a scan-heavy PDF won't shrink much.&lt;/p&gt;

&lt;p&gt;The implementation that actually produced useful results was to re-deflate streams myself with &lt;strong&gt;pako&lt;/strong&gt; at a chosen level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// pdf-lib's internal pako defaults to roughly level 6.&lt;/span&gt;
&lt;span class="c1"&gt;// Re-deflating lets us expose a real Low/Medium/High choice.&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reCompressStreams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PDFLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdfBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;updateMetadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// for each content stream: inflate -&amp;gt; deflate at `level`&lt;/span&gt;
  &lt;span class="c1"&gt;// (pdf-lib exposes the parsed objects; raw stream re-encode is done manually)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two honest caveats I had to surface in the UI:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Low compression can make the file bigger.&lt;/strong&gt; If the original was deflated at level 9, re-deflating at level 1 grows it. That's not a bug, and pretending otherwise produces angry users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image-heavy PDFs barely move.&lt;/strong&gt; A 20MB scanned document is 19MB of JPEG. Flate won't help. Telling the user "this file is already image-compressed, expected savings are small" is better than silently returning a 19.8MB file.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Encryption: pdf-lib has none
&lt;/h2&gt;

&lt;p&gt;This is the biggest gap. &lt;code&gt;pdf-lib&lt;/code&gt; explicitly does not implement the PDF standard security handler (it's issue #243 in the repo, open for years). It can read an encrypted file with &lt;code&gt;ignoreEncryption: true&lt;/code&gt;, but it cannot decrypt it properly or write one.&lt;/p&gt;

&lt;p&gt;So encrypt/decrypt runs through a separate layer that implements the ISO 32000 standard security handler on top of pdf-lib's parsed object graph, using the Web Crypto API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// key derivation is the fiddly part — AES-256 (R6) or RC4-128 (R4)&lt;/span&gt;
&lt;span class="c1"&gt;// AES-CBC for R6, per the spec's block format&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;importKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'raw'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fileKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'AES-CBC'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'encrypt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'decrypt'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things bit me here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Object streams.&lt;/strong&gt; &lt;code&gt;pdf-lib&lt;/code&gt; decompresses object streams at load time and you can't see the original structure. If a producer stores the encryption dictionary inside a compressed object stream, you get a file you can't safely rewrite. The layer has to detect this and refuse rather than emit a corrupt PDF.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key length is derived from &lt;code&gt;/Length&lt;/code&gt;, not assumed.&lt;/strong&gt; A file encrypted with 40-bit RC4 and a file with AES-256 need completely different code paths. Hardcoding one silently produces files that open in some readers and fail in others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empty user password is common.&lt;/strong&gt; Plenty of "protected" PDFs are decryptable with an empty password — they only carry an owner password. Handling that case turns a scary error into a one-click fix.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Memory is the real ceiling
&lt;/h2&gt;

&lt;p&gt;Mobile browsers are where this design gets tested. A few things that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every &lt;code&gt;arrayBuffer()&lt;/code&gt; you hold is a full copy of the file. Two copies of a 200MB PDF will kill an iOS tab.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PDFDocument.load()&lt;/code&gt; keeps the whole object graph in memory. There's no streaming mode.&lt;/li&gt;
&lt;li&gt;Result blobs should be released. &lt;code&gt;URL.createObjectURL()&lt;/code&gt; leaks for the lifetime of the document unless you &lt;code&gt;revokeObjectURL&lt;/code&gt; it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The practical limits I settled on are conservative, and I check &lt;code&gt;navigator.deviceMemory&lt;/code&gt; where available to warn earlier on low-end Android rather than letting the tab get OOM-killed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it genuinely offline
&lt;/h2&gt;

&lt;p&gt;Being client-side isn't the same as being offline. Two more pieces:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A service worker with cache-first for static assets&lt;/strong&gt;, and network-first for the licence API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/api/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;respondWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// never cache auth&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Everything inlined in one HTML file.&lt;/strong&gt; Roughly 3.2MB, which sounds bad and mostly isn't: it's one request, cached once, and every subsequent tool opens instantly because the libraries are already parsed.&lt;/p&gt;

&lt;p&gt;The tradeoff is real though — I can't tree-shake, and every code change to a shared utility touches a 3MB file.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Split the libraries out behind a lazy import&lt;/strong&gt; once the page is cached by the SW. Inlining wins the first load, loses on maintainability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Put compression in a Web Worker from day one.&lt;/strong&gt; Long &lt;code&gt;save()&lt;/code&gt; calls block the main thread, and a frozen tab on a 50MB file looks like a crash.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test on a 200MB file before writing the UI.&lt;/strong&gt; It changes the whole interaction model — you need progress, cancellation, and a hard refusal path.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Was it worth it?
&lt;/h2&gt;

&lt;p&gt;For this specific product, yes, because "your files never leave your device" is the entire value proposition, not a feature bullet. If you're building a PDF tool where the upload is incidental, a small server with Ghostscript and qpdf will beat this approach on both quality and code volume.&lt;/p&gt;

&lt;p&gt;But if the promise &lt;em&gt;is&lt;/em&gt; the privacy, the browser can keep it. You just have to give up the two tools that do the heavy lifting on the server, and be honest about what's left.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you want to see the result: &lt;a href="https://ipdfverse.com" rel="noopener noreferrer"&gt;ipdfverse.com&lt;/a&gt;. The tools are offline; the article above is the architecture behind them.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>pdf</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
