Skip to main content
PulsarKit

Compressing a PDF to an Exact File Size, Not Just 'Smaller'

Ordinary PDF compression gives you whatever size happens to come out. Hitting an exact number, for an email or upload limit, is a different job.

By PulsarKit · ·

A quality level and a target size are two different requests

Picking a compression quality level (light, recommended, aggressive) and finding out what size the result happens to land at is the ordinary way most compression works, and it is the right tool when quality is the concern. Needing a file under a specific number instead, twenty-five megabytes for an email attachment or two megabytes for a web form's upload limit, is a different request. A single fixed quality setting has no way of knowing in advance what size it will produce on any particular document. Hitting an exact number means working backwards from the size rather than forwards from a quality choice. The question changes from "how good should this look" to "how small does this have to be", and the second question needs a different process to answer it.

Reaching a number means searching, not guessing once

The only reliable way to hit a target size is a search, which is what the target mode of Compress PDF runs: try a quality setting, measure the rebuilt file, and adjust up or down based on how far off it landed, repeating that a handful of times rather than picking one number and hoping it works. Each attempt means fully re-encoding every image in the document, which is why this kind of targeted compression takes noticeably longer than a single fixed-quality pass. That extra time is the cost of hitting a specific number instead of an approximate one. A sensible process stops as soon as the result lands just under the target, rather than shrinking the file further than it needs to be, since searching past that point only costs time without improving anything that matters.

Some targets are simply below what's physically possible

Text, embedded fonts and vector drawings inside a PDF have a fixed weight that no amount of image compression can reduce, because none of that content is a raster image in the first place. If a document's fonts and text alone already exceed the size you are asking for, no quality setting will ever get there. Measuring what the file weighs with no images at all, before starting the search, reveals that floor up front instead of after several minutes of fruitless attempts. Being told the smallest achievable size at the start is a far better outcome than a tool that overshoots the target without saying so and hands back a file bigger than what was asked for.

Text stays sharp regardless of the size target

Only the raster images embedded in a document get re-encoded during this kind of compression. Real, selectable text is never touched, however aggressive the size target, so a contract that is mostly text stays as sharp and searchable at the smallest achievable size as it was at the largest. The exception is a page that is a scan. Since the whole page is itself one image, an aggressive size target does visibly soften the writing on it, because there is no separate text layer underneath a scanned page to leave untouched.

When even the smallest number possible isn't small enough

A document can have more pages of raster content than any size target allows for, and the answer at that point isn't a smaller number. It is fewer pages. Splitting the file with Split PDF and compressing each part to the target separately works because that size floor scales with page count. Removing pages that aren't needed for whatever the size limit is for, with Delete pages, works too. Converting a text-heavy document to plain text with PDF to Text first is a third, more drastic option, worth knowing about for the rare case where even that isn't enough.

What the numbers mean: DPI, quality and the floor

Two numbers decide the weight of every image in a PDF. Resolution sets how many pixels there are to store: an A4 page scanned at 300 DPI holds about 8.7 million, the same page at 150 DPI a quarter of that, and at 96 DPI roughly a tenth. JPEG quality sets how many bytes each pixel may keep: 85 is close to the original, 45 makes photographs visibly softer. Resolution is the blunter lever, so the target mode of Compress PDF tries quality first, but only down to 45, the quality of its Extreme level: rather than go any lower, it lowers the resolution.

The search starts at quality 65 and tries 45 next, both at full resolution. If the file is still too heavy, images are capped at 300, 150, 96 and finally 72 DPI, each step at quality 45, and a step that would not change this document's images is skipped; only at 72 DPI does the quality go down to 20. On the first step where the file fits, the quality is raised again towards the target, and the search stops as soon as the file lands between 90 and 100 percent of it, after eight builds at most, so a 1 MB request usually comes back at 0.9 to 1 MB. Quality 20 at 72 DPI is the practical floor: it is measured as soon as a file is open in target mode, and lower targets are locked.

Tools used in this article

Read next