<?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: Woody WK</title>
    <description>The latest articles on DEV Community by Woody WK (@filecpu).</description>
    <link>https://dev.to/filecpu</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%2F4235936%2F421a9d1d-4165-4ea4-8904-ceaec42570ff.png</url>
      <title>DEV Community: Woody WK</title>
      <link>https://dev.to/filecpu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/filecpu"/>
    <language>en</language>
    <item>
      <title>Building a browser-only PDF toolkit: pdf-lib, Web Workers, and what broke</title>
      <dc:creator>Woody WK</dc:creator>
      <pubDate>Mon, 09 Nov 2026 21:57:10 +0000</pubDate>
      <link>https://dev.to/filecpu/building-a-browser-only-pdf-toolkit-pdf-lib-web-workers-and-what-broke-5274</link>
      <guid>https://dev.to/filecpu/building-a-browser-only-pdf-toolkit-pdf-lib-web-workers-and-what-broke-5274</guid>
      <description>&lt;p&gt;Most "free online PDF" sites upload your file to a server. I wanted the opposite: a toolkit where the file never leaves the device. That constraint changes almost every implementation decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why browser-only is harder than it sounds
&lt;/h2&gt;

&lt;p&gt;PDF manipulation is CPU-heavy. Doing it on the main thread freezes the UI for seconds on a 40-page document. The fix is to push every operation into a Web Worker:&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="nx"&gt;worker&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;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/assets/pdfOps.worker.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;pdf-lib&lt;/code&gt; inside the worker, merging and splitting stay responsive. The trade-off is that you can no longer touch the DOM from the parsing code, which forces a clean message-passing boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compression is the part nobody warns you about
&lt;/h2&gt;

&lt;p&gt;There are two very different kinds of "compress a PDF":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Lossless-ish&lt;/strong&gt;: re-encode streams, drop unused objects. Text stays selectable. Savings are modest, often 10-30%.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rasterise&lt;/strong&gt;: render each page to an image and rebuild the PDF. Savings can be 80%+, but you lose selectable text, links and accessibility.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Most tools quietly do (2) and call it compression. If a document needs to stay searchable or screen-reader friendly, that is a real regression. The honest approach is to expose both and say which is which.&lt;/p&gt;

&lt;h2&gt;
  
  
  Archive handling
&lt;/h2&gt;

&lt;p&gt;ZIP is easy (&lt;code&gt;JSZip&lt;/code&gt;). RAR and 7Z are not - they need dedicated decoders, and doing it in the browser means shipping a worker bundle measured in hundreds of kilobytes. Worth it only if archive extraction is a core feature rather than a checkbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I ended up with
&lt;/h2&gt;

&lt;p&gt;A static single-page app: no upload endpoint, no account system, no server-side file handling. Everything runs client-side, so "we delete your file" is not a promise - there is nothing to delete.&lt;/p&gt;

&lt;p&gt;If you want to see the result, it is at &lt;a href="https://filecpu.com" rel="noopener noreferrer"&gt;FileCPU&lt;/a&gt; - free, no signup, and it covers PDFs, images and archives.&lt;/p&gt;

&lt;p&gt;The main lesson: &lt;strong&gt;when you remove the server, you inherit the performance budget.&lt;/strong&gt; A worker-based design is not an optimisation, it is the only way the thing is usable.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
  </channel>
</rss>
