A three-page PDF made of selectable text and a PDF made from scanned pages can react very differently to the same compression setting. If you are trying to meet an attachment limit, keep the original and compare the output size and what you can actually read or select.
Results with two generated PDFs
I tested a 3,248-byte text PDF and a 3,782,988-byte PDF made from two noisy grayscale JPEGs, using synthetic data. The table shows output sizes in bytes.
| Tool |
Searchable text PDF |
JPEG-based PDF |
| PDF Fan |
2,040 |
830,008 |
| iLovePDF |
2,549 |
415,758 |
| Ghostscript 10.05.0 |
4,055 |
3,027,988 |
| qpdf 12.0.0 |
2,035 |
3,782,237 |
I used the recommended setting for both browser tools, the /ebook preset for Ghostscript, and Flate recompression with object streams for qpdf. I work on the PDF Fan toolkit, one of the tools in the table.
In this test, qpdf cut about 37% from the text PDF and about 0.02% from the JPEG-based file. The qpdf command focused on PDF objects and Flate streams and left the JPEG streams as they were. Ghostscript’s ebook preset shrank the JPEG-based file by around 20% and made the small text PDF larger. The two browser presets also produced smaller JPEG-based files. The byte counts describe these inputs and presets. Your scan’s resolution, compression and small-print legibility can change the result.
Repeat the test on your machine
Save the Python below as make_compression_samples.py. Run it with Pillow 13.0.0 and ReportLab 4.4.9. It creates both inputs without personal documents. JPEG encoder versions can affect the starting size.
Show the Python script
"""Generate two synthetic PDFs for a reproducible compression comparison."""
import argparse
import io
import random
from pathlib import Path
from PIL import Image, ImageDraw
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
def text_sample(path: Path) -> None:
pdf = canvas.Canvas(str(path), pagesize=(612, 792), invariant=True)
for page in range(1,
更多...