Back to all guides

Understanding PDF Compression: Balancing Quality and File Size

A deep dive into how PDF compression algorithms work, when to use lossy vs lossless compression, and how to find the right balance for your needs.

7 min
·2026-03-04

The Fundamentals of PDF Compression

Compression in PDF documents operates at multiple levels. Unlike simple file formats where a single compression algorithm is applied to the entire file, PDFs allow different compression methods for different content streams within the same document. Text content, vector graphics, and raster images each have different characteristics that respond differently to compression algorithms, and the PDF format leverages this by allowing per-stream compression choices.

At the most basic level, PDF compression reduces file size by eliminating redundancy. Lossless compression identifies patterns in the data and represents them more efficiently, allowing perfect reconstruction of the original data. Lossy compression goes further by discarding information that is deemed less important, achieving greater size reduction at the cost of some quality loss. The art of PDF optimization lies in choosing the right compression method and settings for each type of content.

The PDF specification supports several compression filters that can be applied to content streams: Flate (zlib/deflate), LZW, JPEG (DCT), JPEG2000 (JPX), CCITT Group 3 and 4, JBIG2, and Run Length Encoding. These filters can even be chained, applying multiple compression passes to the same stream. Understanding what each filter does well and where it falls short is essential for effective PDF optimization.

Lossless Compression Methods in PDF

Lossless compression preserves every bit of the original data and is essential for content where accuracy matters, such as text, line art, and documents destined for printing or archival. The primary lossless compression method in modern PDFs is Flate compression, based on the deflate algorithm (the same algorithm used in ZIP files and PNG images). Flate compression typically achieves a 2:1 to 10:1 compression ratio on text-heavy content streams, depending on the redundancy in the data.

LZW (Lempel-Ziv-Welch) compression is an older lossless method that was widely used before patent concerns led to its replacement by Flate in most applications. LZW is still supported in the PDF specification and may be encountered in older documents, but Flate generally achieves equal or better compression ratios and is universally recommended for new documents.

For monochrome (1-bit) images, CCITT Group 4 compression is highly effective. Originally designed for fax transmission, CCITT Group 4 exploits the fact that most pixels in a typical document page are white, and black pixels tend to cluster in predictable patterns (text characters, line drawings). A 300 DPI monochrome scan of a text page can be compressed from about 1 MB uncompressed to 30-50 KB with CCITT Group 4, a ratio of 20:1 or better.

Lossy Compression: JPEG and JPEG2000

JPEG (DCT-based) compression is the most common lossy compression method for photographic content in PDFs. JPEG works by transforming image data into the frequency domain using the Discrete Cosine Transform, then quantizing the frequency coefficients, discarding high-frequency detail that is less perceptible to the human eye. The quality setting (typically 1-100) controls how aggressively the quantization discards data.

JPEG quality settings exhibit a non-linear relationship with both file size and visual quality. Reducing quality from 100 to 85 typically reduces file size by 50-70% with virtually no visible quality loss. Reducing from 85 to 60 yields another significant size reduction with subtle quality degradation visible only on close inspection. Below quality 40, compression artifacts (blocking, ringing, and color banding) become clearly visible. For PDF documents intended for screen viewing, quality 60-75 is usually the sweet spot. For documents that may be printed, quality 75-85 is recommended.

JPEG2000 is a more modern compression standard that uses wavelet transforms instead of DCT. It achieves better compression ratios than JPEG at equivalent visual quality, particularly at high compression ratios. JPEG2000 also supports lossless compression, progressive decoding (allowing a blurry preview that sharpens as more data loads), and region-of-interest coding. However, JPEG2000 has higher computational requirements and is not supported by all PDF viewers. It is used in PDF/A-2 and PDF/A-3 archival formats.

JBIG2 Compression for Scanned Documents

JBIG2 is a specialized compression standard designed for bi-level (monochrome) images, particularly scanned document pages. It achieves dramatically better compression than CCITT Group 4 by using pattern matching and symbol dictionaries. JBIG2 identifies repeated shapes on a page (typically characters), stores a single template for each unique shape, and then records the position of each instance. Since a typical document page reuses the same characters hundreds of times, this approach can compress a 300 DPI scanned page to just 5-15 KB.

JBIG2 operates in two modes: lossless and lossy. In lossless mode, each unique shape is stored exactly, preserving every pixel. In lossy mode, similar shapes are merged into a single representative template, further improving compression but potentially substituting characters. This lossy behavior gained notoriety in 2013 when it was discovered that certain Xerox scanners using lossy JBIG2 were silently replacing characters in scanned documents, for example changing "6" to "8" in a construction blueprint.

Despite the risks of the lossy mode, JBIG2 remains one of the most effective compression methods for scanned documents. If using JBIG2, ensure that your tools use either lossless mode or a lossy mode with strict similarity thresholds that prevent character substitution. Some PDF optimization tools allow you to configure the JBIG2 similarity threshold. For documents where textual accuracy is critical (legal, financial, medical), use lossless JBIG2 or CCITT Group 4 instead.

Mixed Content Optimization Strategies

Real-world PDFs typically contain a mix of text, vector graphics, photographs, and scanned content. Optimizing these documents requires applying appropriate compression to each content type. The concept of Mixed Raster Content (MRC) formalized this approach: a page is segmented into layers, typically a foreground layer (text and line art), a background layer (photographic content), and a mask layer (defining which parts of each layer are visible).

MRC segmentation allows text to be compressed with JBIG2 or CCITT Group 4 at high resolution (300+ DPI) while photographs are compressed with JPEG at lower resolution (150 DPI). This combination achieves much better results than applying a single compression method to the entire page. A scanned color page that might be 2 MB as a single JPEG image could be reduced to 100-200 KB with MRC segmentation, with sharper text and acceptable photographic quality.

Not all PDF optimization tools support MRC. Those that do include ABBYY FineReader, Kofax, and certain configurations of Ghostscript. When MRC is not available, you can still optimize mixed content by ensuring that the PDF creation process uses appropriate compression per content type: embedding photographs as JPEG while keeping text and vector art in their native form with Flate compression on the content stream.

Compression Artifacts and Quality Assessment

Understanding compression artifacts helps you choose appropriate settings and evaluate optimization results. JPEG artifacts include blocking (visible 8x8 pixel grid patterns at high compression), ringing (halos around sharp edges), color banding (smooth gradients becoming stepped), and mosquito noise (flickering patterns around edges in areas of high contrast). These artifacts are most visible in solid-color areas adjacent to fine detail, which is exactly the pattern found in text rendered as images.

Quality assessment can be objective or subjective. Objective metrics include PSNR (Peak Signal-to-Noise Ratio), SSIM (Structural Similarity Index), and more modern metrics like VMAF. PSNR measures the ratio of signal to noise in decibels; values above 40 dB generally indicate imperceptible quality loss. SSIM operates on a 0-1 scale where 1.0 means identical; values above 0.95 are typically considered excellent. However, these metrics do not always correlate with perceived quality, as they do not fully model the human visual system.

For practical purposes, the best quality assessment is visual inspection at the intended viewing conditions. View the compressed PDF at 100% zoom on a typical display for screen-optimized documents. For print documents, print a test page and compare it to the uncompressed version. Pay special attention to text readability (especially small text), photographic detail in areas of interest, and smooth gradients. If artifacts are visible under normal viewing conditions, reduce the compression level until they disappear.

Choosing the Right Compression Settings

The optimal compression settings depend on the document's purpose, content, and distribution method. For email attachments of business documents (text with some charts and photos), use Flate compression for text streams, JPEG quality 65-75 for photographs, and downsample images to 150 DPI. This typically produces files under 2 MB for a 10-20 page document.

For web-hosted documents intended for on-screen reading, similar settings apply, with the addition of linearization for fast web view. If the PDF will be viewed on mobile devices, more aggressive image downsampling to 96-120 DPI is acceptable since mobile screens rarely exceed 150 effective DPI at typical viewing distances.

For documents intended for professional printing, preserve full image resolution (300 DPI for photographs, 1200 DPI for line art) and use minimal JPEG compression (quality 85-95) or lossless compression. For archival documents under PDF/A standards, use only the compression methods permitted by the target PDF/A conformance level. PDF/A-1 prohibits JPEG2000 and LZW, while PDF/A-2 and PDF/A-3 allow JPEG2000.

As a general rule, compress once and at the latest possible stage. Repeatedly compressing and decompressing JPEG images causes generational quality loss, where artifacts compound with each cycle. Keep your master documents at full quality and produce compressed versions for specific distribution channels.