PNG optimization — should you do it before PDF embedding?
PNG optimizers are a small ecosystem of tools that reduce PNG file sizes without changing pixel data. They work by trying alternative encoding strategies for the same pixels and picking the smallest result. PNG2PDF already runs a lossless re-encode pass on PNG inputs by default — you'll get the easy 5–25% savings without doing anything. If you want more (especially the lossy palette quantization wins), pre-process before upload.
Why PNG output isn't already optimal
The PNG spec lets you pick:
- The filter type for each row (5 options).
- The zlib compression level (0–9).
- The zlib strategy (default, filtered, huffman_only, RLE, fixed).
- Which optional chunks to include (gAMA, iCCP, tIME, tEXt, ...).
Most encoders pick reasonable defaults but don't search the full space. Photoshop's "Save As PNG" uses zlib level 9 and Paeth filter for every row — a fixed strategy that is good but not best. Most general-purpose image toolkits use similar single-pass defaults. Browser screenshot tools often use lower zlib levels for speed.
An optimizer tries multiple combinations and picks the smallest output for the same exact pixels. Same image, smaller file.
The three-tier optimization ladder
Tier 1: lossless metadata strip. Drop chunks the image doesn't need: tIME (modification time), tEXt (text annotations), zTXt (compressed text), iTXt (international text), bKGD (background color hint, ignored by most viewers), pHYs (DPI hint, irrelevant for PDFs). Saves typically 1–10 KB. Most lossless PNG optimizers offer this as a flag.
Tier 2: lossless re-encode. Re-encode the same pixels with optimal filter selection and zlib parameters. Saves 5–25%, occasionally more for synthetic content. Multi-pass lossless optimizers and aggressive deflate searches belong here.
Tier 3: lossy quantization. Reduce truecolor PNGs to ≤256-color indexed PNGs. Saves 50–80% for content that doesn't strictly need millions of colors (most screenshots, icons, UI mockups, diagrams). Palette quantizers do this.
The results are real
Representative numbers on the same 1920×1080 typical desktop screenshot:
| Mode | Size | Time |
|---|---|---|
| unoptimized truecolor PNG | 625 KB | — |
| fast lossless re-encode | ~590 KB | 1 s |
| exhaustive lossless re-encode | ~515 KB | 15 s |
| aggressive deflate search | ~495 KB | 120 s |
| lossy palette quantize, near-perfect | ~185 KB | 2 s |
| lossy palette quantize, more aggressive | ~140 KB | 2 s |
The lossy step is the dominant savings. For screenshots and UI graphics, palette quantization at high quality produces near-indistinguishable results at 1/3 the size.
When optimization isn't worth it
- Single-shot PDFs you'll throw away. If you're making a one-time PDF for sharing, the time spent optimizing PNGs may exceed the bandwidth saved.
- Photographic content. Truecolor photos don't palettize well; lossless re-encoding saves only a few percent. JPEG is the right answer.
- Already-small PNGs. Below 100 KB, optimization typically saves 5–10 KB — not worth the time.
When optimization is worth it
- Documentation and screenshots. Build pipelines that ship docs as PDFs benefit from a lossless optimization pass: 20% smaller PDFs at no quality cost.
- Large multi-PNG PDFs. Combining 50 screenshots? Optimization compounds — total PDF size drops by 20% × 50 inputs.
- Web distribution of PDFs. Bandwidth costs are real; smaller is always better for downloads.
When you want more aggressive optimization
PNG2PDF's built-in pass is lossless and conservative. For deeper savings — palette quantization, exhaustive deflate searches — drop a dedicated optimizer into your build before files reach PNG2PDF. Most static-site generators ship this as an "optimize images" plugin out of the box.
Compressing the PDF after the fact
Tools like our pdfcompressor parse a PDF, identify embedded images, optionally recompress them at lower quality, and rewrite the PDF. This works on PDFs from any source and can apply lossy compression that makes sense per-image type.
For a workflow where you don't control PNG generation but want compact PDFs, this is the right tool. The optimization happens after PDF assembly rather than before.