Compress PDF to Size

Published Updated

Compress a PDF to a target size — free and processed entirely in your browser.

Two stages, and the second one changes your PDF

You give the tool a size and it tries to hit it. It starts with a rewrite of the file structure, the same pass as the plain compressor. If the result is under your target, it stops, and your text and images are exactly as they were.

If not, it falls back to rasterising: every page is drawn to an image and the PDF is rebuilt from those images. Text stops being text, so this is the same trade-off you get with a scan.

How the second stage searches

It tries four resolutions in order and stops at the first one that fits. At each resolution it looks for the highest JPEG quality between 20% and 92% that stays under the target, using six rounds of halving.

ResolutionA4 page in pixelsPixels per page
150 DPI1,241 × 1,7542.18 million
120 DPI993 × 1,4041.39 million
96 DPI794 × 1,1230.89 million
72 DPI596 × 8420.50 million

Quality is shared by all pages, because the target applies to the whole document. If even 72 at 20% quality is too big, the flattened attempt is kept only when it is smaller than the best lossless result. When it is not, the lossless result is returned instead, and when the lossless pass saved nothing at all, you get your original file unchanged with a message saying so, so the tool never hands back a file larger than the one you gave it.

Setting a target and compressing

  1. Step 1

    Add a PDF

    The page counts the pages and shows the file size. A file already under your target is returned as it is.

  2. Step 2

    Set the target

    Pick 500 KB, 1 MB or 5 MB, or type your own value in KB or MB. Sizes are binary, so 1 MB means 1,048,576 bytes.

  3. Step 3

    Compress and read the message

    The result card says whether lossless optimisation was enough or pages had to be turned into images, and whether the target was reached.

Before you rely on the result

  • Binary units: 500 KB is 512,000 bytes and 5 MB is 5,242,880 bytes.
  • Pages keep their look but not their selectable text once they are images. Check the first page at full zoom.
  • Photographs and scans survive rasterising well. Small text and thin lines are what suffer at 96 and 72 DPI.
  • Rebuilt pages keep the size of the source pages in points, whichever resolution is used.
  • If you only want the lossless pass, PDF Compressor does that without ever rasterising. Password-protected files must be opened with Unlock PDF first.

Worked example: two generated PDFs and eight targets

Two synthetic PDFs were generated by script. The first, a scan-like file, has 4 A4 pages that are JPEG photographs with no text, 1,797,165 bytes. The second, made with ReportLab, has 30 pages of plain text lines, 31,487 bytes, and pdf.js read 106,188 characters from it. The tool's compression function was bundled into a test page and run in Chromium 153.0.8010.12 (the build bundled with Playwright, run headless), with the page text read back by pdf.js after each run. Times are from one Mac.

File and targetStage that produced the resultResult sizeText left
Scan, 2 MB (2,097,152 B)Lossless rewrite only1,796,591 B (574 B smaller)none to begin with
Scan, 1 MB (1,048,576 B)Rasterized at 150 DPI1,043,850 Bnone to begin with
Scan, 500 KB (512,000 B)Rasterized at 150 DPI504,503 Bnone to begin with
Scan, 200 KB (204,800 B)Rasterized at 150 DPI200,577 Bnone to begin with
Scan, 50 KB (51,200 B)Rasterized at all four resolutions, target missed60,748 B (at 72 DPI)none to begin with
Text, 100 KB (102,400 B)Lossless rewrite only24,348 B106,188 of 106,188 characters
Text, 20 KB (20,480 B)Lossless rewrite kept, target missed (flattening would have been larger)24,348 B106,188 of 106,188 characters
Text, 5 KB (5,120 B)Lossless rewrite kept, target missed (flattening would have been larger)24,348 B106,188 of 106,188 characters

The search lands close under the target: 99.5, 98.5 and 97.9 percent of it in the three runs that needed it. The row to look at is the text file. Its lossless result, 24,348 B, was 3.9 KB above the 20 KB target. Flattening its 30 pages into images at the lowest resolution and quality came to 1.77 MB, so the tool keeps the smaller lossless file, with all 106,188 characters still selectable, and the result card says the target was not met.

Timing: the 4-page scan took 0.6 to 1.0 s per target. The 30-page text file took about 6.2 s when it went through all four resolutions before the lossless file was kept.

Why the quality search stops where it does

Each candidate quality is passed to canvas.toBlob, whose quality argument is a number from 0 to 1 that applies to lossy formats such as JPEG (MDN, toBlob). The tool tries 0.92 first, then 0.2, then halves the gap six times, so one search tests at most 8 values and keeps the highest one that fits; when the page and image objects push the finished PDF over the target, the search runs once more with that overhead taken off. That is why results land a little under the target and not exactly on it. On the lossless side, pdf-lib's save option for object streams (pdf-lib, SaveOptions) is the only change made, which is why the text file kept all of its characters and shrank from 31,487 B to 24,348 B.

Compressing a PDF to a target size

Why can I no longer select the text after compressing?

The first attempt is lossless and keeps text. If that cannot reach your target, every page is rendered as a JPEG image and the PDF is rebuilt from those images. Text, links, form fields and bookmarks do not survive that step. The result card tells you which path was taken.

My upload limit is 1 MB. What should I enter?

Many portals count 1 MB as 1,000,000 bytes, while this tool counts 1,048,576. For a safe margin type 950 KB, which is about 973,000 bytes.

What if the tool cannot reach my target?

It returns the smallest result it found: the flattened 72 DPI version when that is smaller than the lossless one, otherwise the lossless file or your original, and marks it as not reaching the target. At that point the options are a larger target, splitting the PDF, or removing pages.

Will the rebuilt pages change size?

No. A rebuilt page matches its source page as a viewer shows it, so A4 stays A4 at every DPI step, and a rotated page stays landscape.

Does it work on password-protected files?

No. Use Unlock PDF first, then come back.

Which is better, this or the PDF Compressor?

PDF Compressor only does the lossless pass, so it never changes your content but may not get far. This tool tries that first and then goes further, up to the point of turning pages into images, to reach a size you name.

Can a smaller target make my PDF bigger?

No. When flattening the pages would give a bigger file than the lossless result, the tool keeps the lossless file (or your original if the lossless pass saved nothing) and says the target was not met. A 31 KB text PDF stayed at 24 KB with a 20 KB target.

How close to my target will the file be?

Under it, by a little. In our three scan runs that needed the second stage, the files came to 99.5, 98.5 and 97.9 percent of the target.

Does a target above my file size change anything?

Almost nothing. With a 2 MB target our 1.80 MB scan came back from the lossless rewrite only 575 bytes smaller, with its content unchanged.

Related guides

How to compress, merge and convert PDFs without uploading them. The guide works through the 150, 120, 96 and 72 DPI steps this tool tries, with measured file sizes for a scanned page at four resolutions.

How to flatten, resize and shrink a PDF. The guide compares compressing before and after removing pages on a six-page file, where removing first kept JPEG quality at 0.92 instead of 0.864.

Related Tools