Skip to content
AgileLogics

Compress PDF

Reduces a PDF's file size by re-encoding embedded JPEG photos at a lower quality (same pixel dimensions) and re-saving the file with compact object streams. Text and vector graphics are left untouched. If the PDF can't be made smaller, the tool says so instead of returning a bigger file.

How it works

Choose a PDF file and click Convert.

What does this PDF compressor actually do?

This tool shrinks a PDF in two steps. First it finds the colour JPEG photos embedded in the file and re-encodes each one at a lower JPEG quality, at exactly the same pixel size, keeping the new version only when it is clearly smaller. Then it re-saves the document with compact object streams. Text, fonts and vector drawings are never touched.

If the finished file wouldn't be smaller than what you uploaded, you get no download, just a message saying the PDF is already as small as this tool can make it, so you never end up with a "compressed" copy that is bigger than the original.

Where a PDF's bytes go

A PDF is a collection of numbered objects (pages, fonts, images, drawing instructions) plus a cross-reference index telling a reader where each object starts (ISO 32000-1, section 7.5). Which kind of document you have decides how much this tool can do:

Kind of PDF Where most bytes are What this tool can save
Scans saved as colour JPEG pages Page photos Often a lot
Photo-heavy brochures and reports Embedded JPEG photos Often a lot
Scans stored as black-and-white or lossless images Page images Little or nothing
Text reports from older software Fonts and many small uncompressed objects Somewhat
Text files written by modern tools Already compact Usually nothing

Which images get recompressed

Inside a PDF, a JPEG photo is stored as an image stream with the DCTDecode filter, which is simply the JPEG file's bytes (section 7.4.8). The tool decodes each one with your browser, draws it onto a canvas of the same width and height, and saves it again as a JPEG at quality 0.6. To stay safe, it only touches images that are plain 8-bit colour JPEGs (DeviceRGB or an RGB ICC profile). It skips:

  • images with a soft mask or mask (transparency), a decode array or extra decode parameters,
  • greyscale, CMYK and indexed-colour JPEGs,
  • any image that isn't a JPEG at all, such as Flate-compressed (PNG-style) images,
  • images larger than 40 million pixels, and anything the browser can't decode.

A re-encoded photo replaces the original only if it is at most 90% of the old size. Placement on the page is unchanged, because the image keeps its dimensions and the page's drawing instructions aren't edited.

A worked example

This site's automated tests use a one-page report with a heading and a 480 x 320 photo saved at JPEG quality 0.95. The original file is 79,865 bytes. After compressing it is about 18,400 bytes, roughly 23% of the original, and the heading text is byte-for-byte identical. Rendered side by side, the two pages differ by about 2 levels out of 255 per colour channel on average, which is invisible at normal zoom.

The same test suite's tiny text-only PDF (854 bytes) shows the other case. It has no photos, and pdf-lib's re-save would have made it 6 bytes larger, so the tool reports that the file is already as small as it can make it and offers nothing to download.

To try it on your own file:

  1. Choose your PDF and click Convert.
  2. If a download appears, save compressed.pdf and compare its size with the original.
  3. Open it and zoom in on a photo to check the quality is acceptable for your use.
  4. If you see the "already as small" message, keep your original; nothing was lost.

What the re-save step changes

Object streams. PDF 1.5 added a way to pack many small objects into one compressed stream and to replace the plain-text cross-reference table with a compressed one (sections 7.5.7 and 7.5.8). Files written the old way shrink a little when those objects are packed.

Collapsed incremental updates. When a program saves edits by appending changes to the end of a file, old versions of changed objects stay behind (section 7.5.6). pdf-lib keeps only the latest version of each numbered object when it writes the file back out.

pdf-lib does not delete objects that nothing refers to, merge duplicate fonts, subset fonts or downsample images. Every PDF tool on this site saves with object streams, so a file you've already merged, split or rotated here will only shrink further if it contains JPEG photos.

When you need an even smaller file

  • Before the PDF exists: shrink photos first with the image resizer and image compressor, then convert with JPG to PDF. A 4000-pixel-wide phone photo is far more than a document page needs, and this tool keeps the pixel count as it is.
  • Remove what you don't need: dropping pages with Split PDF is often the quickest saving of all.
  • On your own machine: Ghostscript's pdfwrite device can downsample images too. Its -dPDFSETTINGS=/ebook preset targets 150 dpi colour images and /screen targets 72 dpi (Ghostscript documentation).

Limits

Password-protected PDFs and PDFs with permission restrictions are rejected: pdf-lib won't load any file with an encryption dictionary, and you'll see "Could not compress that PDF:" followed by a message saying the document is encrypted. Bookmarks, form fields and the document title and author are kept; pdf-lib updates the producer and modification date. There's no file size cap in the code, but the whole file and each photo being re-encoded are held in memory while it works.

Last updated

Frequently asked questions

How much smaller will my PDF get?
It depends on what the PDF contains. Files whose weight is in JPEG photos, such as many scans and brochures, often shrink a lot because those photos are re-encoded at a lower quality. Text-only files gain little or nothing. If the result wouldn't be smaller than the original, the tool tells you so instead of handing back a bigger file.
Will compressing reduce the quality of images or text?
Text, fonts and vector drawings are copied unchanged, so they stay perfectly sharp. Recompressed JPEG photos keep their pixel dimensions but are saved at a lower JPEG quality, so fine detail and smooth gradients can show slight softening or blockiness if you zoom in.
Why didn't my PDF get smaller?
Only plain colour JPEG photos are recompressed. Text-only files, images stored losslessly (PNG-style), JPEGs with transparency, and greyscale or CMYK JPEGs are left as they are, and the tool doesn't downsample images, subset fonts or remove unused objects. When nothing can be saved you'll see a message saying the PDF is already as small as this tool can make it.
Is my PDF uploaded to be compressed?
No. The file is opened by the pdf-lib library and its photos are re-encoded by your browser's own image engine, all on your device. Nothing is sent to a server.