Why PDF compression quietly turns your text into a picture
Description and use
Compressing PDFs can strip text; using PDFLib to deflate unfiltered streams keeps all characters while reducing size.
Problem
Compressing a text PDF often results in a rasterized image, losing selectable text.
Outcome
The lossless repack reduced file size by 3.4× compared to the best raster result while keeping all text selectable.
Workflow
- Load source PDF
- Copy pages into a fresh document
- Save with useObjectStreams:true
- Identify raw streams without /Filter
- Deflate those streams with FlateDecode
- Replace original streams with compressed ones
- Preserve original if deflate not beneficial
- Re‑save document
Evidence
A 6-page text PDF went from 298.7 KB to 8.9 KB with every one of its 26,652 characters still selectable.
Lossless came out 3.4× smaller than the best raster result, and it was the only row where the text survived at all.
Walk every indirect object in the document. For each raw stream whose dictionary has no /Filter, deflate it and label it…
- Record date: 2026-10-21T08:41:12.335Z