Technology Sep 03, 2026 · 2 min read

I built a PDF compressor that never uploads your file — here's the actual technique

Added PDF compression to ToolHub, and wanted to write up the actual approach since it wasn't as simple as "just use an API." The obvious easy path was a third-party compression API — but that would mean uploading the user's PDF to someone else's server, which directly contradicts the "nothing leave...

DE
DEV Community
by Anas Khalid
I built a PDF compressor that never uploads your file — here's the actual technique

Added PDF compression to ToolHub, and wanted to write up the actual approach since it wasn't as simple as "just use an API."

The obvious easy path was a third-party compression API — but that would mean uploading the user's PDF to someone else's server, which directly contradicts the "nothing leaves your browser" thing the rest of the site is built around. So instead: each page gets rendered to an image (reusing the same pdf.js pipeline from an earlier PDF→PowerPoint feature), recompressed with a quality slider using the same canvas technique the Image Compressor already uses, then rebuilt into a new PDF with pdf-lib. Entirely client-side, zero uploads.

Before touching the real browser code, I tested the whole pipeline in a Node harness — generated a 4.7MB image-heavy test PDF, ran it through the compression logic, got a genuine 72% size reduction, then independently verified the output with pypdf (extracted the actual embedded image and visually confirmed it wasn't corrupted, not just "the script ran without erroring").

One honest tradeoff worth mentioning: since each page becomes a compressed image, text in the output isn't selectable anymore. Stated plainly in the tool itself rather than hidden — the right fit for image-heavy PDFs (scans, photo-heavy docs), not for anything where staying searchable matters.

ToolHub-PdfCompressor

DE
Source

This article was originally published by DEV Community and written by Anas Khalid.

Read original article on DEV Community
Back to Discover

Reading List