DEV Community

Witplay Tools
Witplay Tools

Posted on Edited on

Shipping browser PDF tools that never upload your file

Most "free online PDF tools" work the same way: you upload the file to someone's server,
a quality slider appears, and you hope the export lands under the limit the portal wants
(100 KB for a form, 2 MB for an email attachment). I wanted the opposite: tools where the
file never leaves the tab, and the size cap is an input, not a slider you guess with.

Three things made that harder than it looks.

1. The PDF worker has to be inlined, or file:// breaks.
pdf.js runs most of its parsing in a worker loaded by URL. A single-file build has no
sibling files to load, so the worker is inlined as a Blob and GlobalWorkerOptions.workerSrc
is pointed at URL.createObjectURL(blob). The catch: on file:// the document origin is
opaque, and a few engines refuse Blob workers there. Wrapping the worker source in a plain
data: URL avoided that for me, at the cost of a slightly larger bootstrap. pdf-lib has no
worker, so merge/split stayed simple: copy pages instead of re-rendering, which keeps text
selectable and keeps file size predictable.

2. "Compress to 100 KB" is a search problem, not a quality setting.
Every online compressor asks for a percentage. What people actually need is "make it fit".
So the tool does a bounded search: encode at high quality, if it overflows step quality down;
when quality alone cannot fit (a 4000 px scan at q=0.4 is still 2 MB), step resolution down
in 10% increments and retry. Cap the loop at ~10 encodes and stop at the first result under
the target, remembering the last good one. Worst case measured here: a 10.5 MB PNG of pure
noise becomes a 96 KB JPEG at target 100, in about four seconds in a normal tab.

3. HEIC is a library you must ship, not a format the browser knows.
Safari decodes HEIC; Chrome does not. heic2any pulls in libheif, and it is heavy, which is
why the concatenated single file for the converter is 3.6 MB. It is worth it: a user drags an
iPhone photo in, gets a JPEG at the original pixel dimensions, no server round trip.

The result is a folder of HTML files you double-click. No install, no admin rights, no
account, no telemetry, works on a plane. Libraries inlined means the first run is also the
only load.

If you want to poke at it, the image compressor version is running free on GitHub Pages:
https://witplay.github.io/offline-tools/ — drag a big photo in, set the KB cap, watch it search.

The offline single-file builds and the PDF/HEIC tools are paid, since each one gets tested
against real portal caps: https://witplay.gumroad.com/l/offline-document-kit

(I am not going to pretend this is a startup — it is three tools I got tired of uploading
contracts to random websites to use.)

Top comments (0)