Compress PDF
Try to reduce an image-heavy PDF by locating compatible embedded image streams, scaling them to at most 800 pixels on their longest side, and re-encoding them as low-quality JPEG. There is no adjustable compression level, and text-only or already optimized PDFs may not shrink.
What this PDF compressor actually changes
The implementation targets raw PDF image streams rather than applying a general-purpose optimizer to every object. Compatible images are decoded in the browser, optionally downscaled, and written back as JPEG at a fixed quality value of 0.15.
This is aggressive, fixed image recompression. It may suit screen-only scans or handouts where small size matters more than fine detail, but it is not appropriate for archival, prepress, medical, legal-evidence, or other fidelity-sensitive material.
How to use this tool
- Select a PDF: Choose the file and review the first-page preview when available.
- Keep the original: The compression settings are fixed and aggressive, so retain an untouched source copy.
- Compress: Run the operation while the browser scans raw streams and attempts to recompress compatible images.
- Compare and inspect: Compare byte sizes and open the download. Check small text, diagrams, forms, links, signatures, and representative pages.
Input and output
Input
- One PDF that pdf-lib can load and whose targeted image streams the browser can decode
Output
- One new PDF downloaded with compressed_ prefixed to the source filename
How embedded images are recompressed
Inspect raw streams
pdf-lib enumerates indirect objects and selects raw streams whose subtype is Image.
Decode and downscale
The browser attempts to decode each selected stream as JPEG or PNG. Images larger than 800 pixels on either dimension are proportionally reduced.
Re-encode as JPEG
Successfully decoded images are exported as JPEG at fixed quality 0.15 and the PDF image dictionary is updated.
Rewrite the PDF
pdf-lib serializes the modified document with object streams enabled. Streams that cannot be decoded are left unchanged.
Reducing a scanned handout
- Scenario
- A scanned classroom handout is too large for an attachment limit.
- Action
- Compress it, compare the new byte size, and zoom into small print.
- Input
- A PDF whose pages primarily contain large scanned images
- Expected result
- Compatible scans may become much smaller and visibly softer. The implementation cannot promise a target size or any reduction for PDFs without compatible image streams.
Important quality and compatibility limits
- There is no quality slider, target-size input, or selectable compression level.
- JPEG quality is fixed at 0.15 and image dimensions are capped at 800 pixels, which can substantially soften scans and diagrams.
- Only compatible raw image streams are targeted; other PDF content and unsupported image encodings remain unchanged.
- Transparency and colour behavior can change when non-JPEG image data is rewritten as JPEG.
- The result can be similar in size or larger than the source.
- Document-level forms, links, metadata, accessibility tags, and signatures must be checked after rewriting; cryptographic signatures should not be assumed valid.
- Processing large or complex PDFs can exhaust browser memory.
Frequently Asked Questions
Can I choose a lighter compression setting?
No. The current implementation uses a fixed JPEG quality and an 800-pixel maximum dimension for compatible embedded images.
Why did the PDF barely shrink?
It may contain mostly text or vectors, already optimized images, or image encodings that the browser path cannot decode and replace.
Why does scanned text look softer?
Scanned text is part of an image. Downscaling and low-quality JPEG encoding remove image detail along with photographic detail.