Test PDF outputs by converting per-page to images (`pdftocairo` / pdf2image / Poppler) and running pixel-diff (pixelmatch / Resemble.js / Pillow `ImageChops`) against approved baselines. Per-page-range targeting, threshold tuning, font-substitution warnings, byte-stable PDF metadata stripping (CreationDate, /ID). Use when a product generates invoices, contracts, or regulatory filings whose layout must not shift, and a PDF template, font pack, or generation library is about to change.
79
99%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Medium
Suggest reviewing before use
Non-deterministic PDF metadata and host font substitution are the two environment factors that invalidate baselines. Normalize both before diffing, or rely on image diff (which is metadata-free by construction).
PDFs include /CreationDate, /ID, sometimes /ModDate. These change
per run and break byte diffs. Use qpdf to normalize:
qpdf --linearize \
--object-streams=disable \
--replace-stream-data=uncompress \
--remove-attachments \
out.pdf normalized.pdfAlternative: rely on image diff (render + pixel-diff) which is metadata-free by construction.
Missing fonts on the rendering host produce visually-different output. Detect via Poppler stderr:
import subprocess
result = subprocess.run(
["pdfinfo", "-list-embedded-fonts", "out.pdf"],
capture_output=True, text=True,
)
if "Font Substitution" in result.stderr:
raise RuntimeError("Font substitution detected; baseline invalid")For CI, install the production font pack via the package manager or check fonts into the repo for deterministic builds.