Field notes

Building a batch PDF engine without a server

Implementation notes on Workers, raster rendering, qpdf encryption and verifiable privacy.

The first release keeps document bytes inside a dedicated Web Worker. pdf-lib handles document construction, PDF.js renders pages to images, and qpdf-wasm performs actual password encryption. Multiple outputs are packaged locally with fflate.

Two integration failures shaped the implementation. PDF.js needed an explicit worker asset URL in the production bundle. The qpdf ESM wrapper also assumed a globals-based Emscripten load, so PlainPDF carries a small Apache-2.0 source adaptation that exports the module factory directly.

The regression suite creates real PDFs, downloads outputs and parses them again. It checks merged page counts, split ZIP contents, page rotation, image conversion, watermarks and compression. For encryption, qpdf rejects a wrong password and decrypts with the correct one before the resulting page count is checked. Network listeners record any unexpected outbound request during the complete suite.

Cancellation terminates the active Worker and marks unfinished files accordingly. Independent files run sequentially, allowing successful outputs to survive a later failure. This is a deliberate memory and recovery boundary, not a claim that every PDF or device has unlimited capacity.