pdfcraft/crates/optimize
Brandon Thomas 414060a3ff
Merge pull request #16 from storytold/pr/never-crash-small
Never crash: filters, fonts, js, optimize and a11y deny the panic lints
2026-10-04 14:46:43 -04:00
..
src Merge pull request #16 from storytold/pr/never-crash-small 2026-10-04 14:46:43 -04:00
tests Optimizer: Audit space usage counts images PrintCraft added as images (#3) 2026-10-04 13:24:06 -04:00
Cargo.toml M11: PDF Optimizer ▸ Audit space usage: bytes and share of the file per kind of content; doc_audit_space 2026-10-02 07:37:48 -04:00
README.md M11.1: PDF Optimizer: new optimize crate measures each image's effective resolution where pages draw it and resamples (bicubic) and recompresses (JPEG quality steps or ZIP) colour and grayscale images, soft masks with them, only when smaller; discards thumbnails, alternate images, tags and print settings; Flate for unencoded streams. Reduce File Size now downsamples like Acrobat (150 ppi above 225, JPEG medium); Optimize PDF dialog (Images, Discard Objects, Discard User Data, Clean Up) composes Remove Hidden Information; doc_optimize tool (84 tools) 2026-10-02 03:18:47 -04:00

README.md

printcraft-optimize

Layer L4: the PDF Optimizer (execution plan M11.1; Acrobat's Reduce File Size and Optimize PDF ▸ Advanced optimization).

let report = optimize(&mut doc, &Settings::default())?;   // Reduce File Size's choices
  • Images: the effective resolution of each image is measured where pages draw it (the CTM through form XObjects; the smallest over all uses). Colour and grayscale images above a threshold are resampled with a bicubic (Catmull-Rom) filter to a target resolution and stored as JPEG (Acrobat's quality steps) or ZIP; soft masks are resampled with their image. An image is replaced only if the result is smaller. Left alone: CMYK and other colour spaces, image masks, decode arrays, more than 8 bits, JPEG 2000, JBIG2 and CCITT.
  • Discard objects: thumbnails, alternate images, document tags, print settings.
  • Clean up: Flate for streams with no filter.

The engine runs Remove Hidden Information (printcraft-redact) for the user-data categories, then this, then merges identical objects and writes a full, compressed save. JPEG decoding and encoding and resampling come from the image crate.