PDF300

How to Compress a PDF with qpdf (Lossless Structural Optimization)

Updated · 4 min read · By

qpdf is a precise, lossless way to tidy up a PDF's internal structure. It is fast, scriptable, and never degrades your text or images. But it is important to understand exactly what it compresses, because people often expect it to crush a photo-heavy file and come away disappointed.

The situation

You want to shrink a PDF without touching quality at all. Maybe it is a legal document where every pixel matters, or a file you will edit again later. qpdf is the right first tool: it reorganizes and compresses the file's plumbing without re-rendering a single page. The question is how much it can actually save, and what to reach for when it is not enough.

Why qpdf shrinks files (and where it stops)

A PDF stores its objects — pages, fonts, metadata, content — as a set of numbered entries with a cross-reference table. Older or naively written PDFs leave this structure loose: objects stored uncompressed, content streams left raw, redundant whitespace, and a sprawling cross-reference section.

qpdf rewrites all of that losslessly. It can pack many small objects into compressed object streams, apply stream compression (Flate/zlib) to content that was left uncompressed, and rebuild a compact cross-reference. None of this changes how the page looks. It is the digital equivalent of zipping up the scaffolding.

Here is the limit, and it is the single most important thing to know: qpdf does not downsample or re-encode images. A JPEG inside your PDF stays exactly as it was. So if your file is 40 MB because it contains high-resolution scans or photos, qpdf will shave off the structural overhead but leave the images untouched — and the images are the real weight. That is why qpdf alone often produces only a modest reduction on image-heavy files, and a larger one on text-and-vector files that were poorly written.

How to compress a PDF with qpdf

Step 1: Compress object and content streams

The core command generates object streams and compresses the content streams:

qpdf --object-streams=generate --compress-streams=y in.pdf out.pdf

--object-streams=generate bundles small objects together and compresses them. --compress-streams=y ensures stream data is Flate-compressed. Together these clean up the structural bloat without any quality loss.

Step 2: Linearize for faster web viewing

If the PDF will be served online, linearizing ("fast web view") reorganizes it so the first page can display before the whole file downloads:

qpdf --linearize in.pdf out.pdf

Linearization is about delivery, not primarily about size; it may even add a few bytes, but it makes large files feel faster to open in a browser.

Step 3: Pair qpdf with image downsampling

For an image-heavy PDF, use qpdf for the lossless structural pass, then downsample the images separately — that is where the big numbers come from. Ghostscript can downsample images, or a target-size tool can do it to a number. PDF300 lets you set the target size and re-encodes the images to fit, which complements qpdf's lossless cleanup rather than competing with it.

Checklist

FAQ

Does qpdf reduce image size inside a PDF?

No. qpdf performs lossless structural optimization: it compresses object and content streams and rebuilds the cross-reference table, but it never downsamples or re-encodes embedded images. For a file whose weight is photos or scans, pair qpdf with a separate image downsampling or target-size step.

What is the difference between object streams and linearization?

Object streams bundle many small PDF objects together and compress them, which reduces file size. Linearization reorders the file so a web viewer can show the first page before the rest downloads; it improves load speed, not size, and can even add a few bytes. They solve different problems and can be used together.

Will qpdf ever make my PDF larger?

Occasionally, yes. Linearizing or rewriting an already well-optimized file can add a small amount of overhead. In practice the gains from object streams and stream compression usually outweigh this, but if a file is already compact, qpdf's structural pass may offer little or a slight increase.

Written by LeDeuxions, an architect who built PDF300 after a 300 MB portal limit kept rejecting drawing sets. Figures quoted from third parties link to their source; sizes and reductions described as "typical" are estimates, not guarantees.