## What Makes a PDF Large?
- **High-resolution images** without compression (most common cause).
- **Full embedded fonts** instead of subsets.
- **Unnecessary metadata and thumbnails**.
- **Scanned without OCR** — one high-res image per page.
## Method 1: Ghostscript (Free, Best Quality Control)
```bash
sudo apt install ghostscript # Ubuntu/Debian
brew install ghostscript # macOS
# Screen quality (72 DPI) — smallest size
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-dNOPAUSE -dBATCH -dQUIET \
-sOutputFile=compressed.pdf original.pdf
# eBook quality (150 DPI) — recommended
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook \
-dNOPAUSE -dBATCH -dQUIET \
-sOutputFile=compressed.pdf original.pdf
# Print quality (300 DPI)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer \
-dNOPAUSE -dBATCH -dQUIET \
-sOutputFile=compressed.pdf original.pdf
```
### PDFSETTINGS Levels
| Level | DPI | Typical reduction |
|-------|-----|-----------------|
| `/screen` | 72 | 80-90% |
| `/ebook` | 150 | 60-80% |
| `/printer` | 300 | 30-50% |
| `/prepress` | 300+ | 10-20% |
## Method 2: qpdf (Structure Compression)
```bash
qpdf --compress-streams=y --object-streams=generate \
original.pdf compressed.pdf
qpdf --linearize original.pdf compressed_web.pdf
```
## Method 3: Python with PyMuPDF
```python
import fitz # pip install pymupdf
def compress_pdf(input_path, output_path, image_quality=60):
doc = fitz.open(input_path)
for page_num in range(len(doc)):
page = doc[page_num]
for img in page.get_images(full=True):
xref = img[0]
pix = fitz.Pixmap(doc, xref)
if pix.n >= 4:
pix = fitz.Pixmap(fitz.csRGB, pix)
doc.update_stream(xref, pix.tobytes("jpeg", jpg_quality=image_quality))
doc.save(output_path, garbage=4, deflate=True, clean=True)
doc.close()
compress_pdf("document.pdf", "compressed.pdf", image_quality=60)
```
## Real-World Results
Test PDF: 20 pages with 15 images — original 45 MB:
| Method | Result size | Quality |
|--------|------------|---------|
| GS `/screen` | 2.1 MB | Good for screen |
| GS `/ebook` | 4.8 MB | Very good |
| GS `/printer` | 12 MB | Excellent |
| qpdf | 43 MB | Identical |
| PyMuPDF (q=60) | 8 MB | Very good |
## Online Tools
- **ilovepdf.com** — free, up to 100 MB.
- **smallpdf.com** — free with limits.
- **Adobe Acrobat online** — free with Adobe account.
⚠️ Don't use online tools with confidential documents.
## Conclusion
For everyday documents: Ghostscript `/ebook` reduces size 70% with excellent quality. For structure-heavy PDFs: qpdf compresses without touching content. For pipeline automation: PyMuPDF gives precise control.
Guide