← Blog

PNG optimization — should you do it before PDF embedding?

Optimizers strip metadata, pick best filters, search for tighter deflate output Lossless re-encoder tries all 5 filters per row tries multiple zlib strategies drops non-essential chunks → 5–25% smaller, fully lossless Lossy palette quantizer re-quantizes to ≤256-color palette → 50–80% smaller, slight color loss Effect on PDF size Smaller PNG → smaller PDF PNG2PDF runs a lossless re-encode pass automatically A 600 KB → 200 KB PNG becomes a similarly small PDF

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:

  1. The filter type for each row (5 options).
  2. The zlib compression level (0–9).
  3. The zlib strategy (default, filtered, huffman_only, RLE, fixed).
  4. 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:

ModeSizeTime
unoptimized truecolor PNG625 KB
fast lossless re-encode~590 KB1 s
exhaustive lossless re-encode~515 KB15 s
aggressive deflate search~495 KB120 s
lossy palette quantize, near-perfect~185 KB2 s
lossy palette quantize, more aggressive~140 KB2 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

When optimization is worth it

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.