Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DilwoarH/pdf-visual-regression/llms.txt
Use this file to discover all available pages before exploring further.
The results.json file
Every comparison generates aresults.json file containing detailed metadata about the test run.
Successful comparison (identical PDFs)
Failed comparison (differences found)
Page count mismatch
Field reference
timestamp
timestamp
The timestamp when the comparison was run, in
YYYYMMDD_HHMMSS format. This matches the output directory name.status
status
Either
"success" (all pages identical) or "error" (differences found). Use this field for automated test assertions.description
description
A human-readable summary of the comparison results. Examples:
"All pages are visually identical.""Visual differences found on pages: 1, 3""Visual differences found on pages: 2 Extra pages only in PDF1: 4, 5"
pdf1 / pdf2
pdf1 / pdf2
Absolute paths to the compared PDF files. Useful for tracing back to source files in automated systems.
pdf1_pages / pdf2_pages
pdf1_pages / pdf2_pages
The number of pages in each PDF. When these differ, a warning is printed during comparison.
threshold
threshold
The SSIM threshold used for the comparison (default:
1.0). Pages with SSIM scores below this value are flagged as different.identical
identical
Boolean indicating whether the PDFs are visually identical. This is
true only when both diff_pages and extra_pages are empty.diff_pages
diff_pages
Array of page numbers (1-indexed) where visual differences were detected. Empty if no differences found.
extra_pages
extra_pages
Array of page numbers that exist in only one PDF. Empty if both PDFs have the same page count.
extra_pages_in
extra_pages_in
Either
"PDF1", "PDF2", or null. Indicates which PDF contains the extra pages.Understanding diff images
Image naming convention
Diff images follow these naming patterns:diff_page_1.png- Visual differences found on page 1diff_page_2.png- Visual differences found on page 2extra_page_4_only_in_pdf1.png- Page 4 exists only in PDF1extra_page_3_only_in_pdf2.png- Page 3 exists only in PDF2
Visual highlighting explained
The tool uses a multi-step process to highlight differences:Compute pixel difference
Uses PIL’s
ImageChops.difference() to find pixels that differ between the two pages.Apply threshold
From pdf_visual_diff.py:63:Pixels with differences greater than 20 (out of 255) are marked. This filters out minor noise.
Create overlay
Differences are highlighted with a semi-transparent red overlay:The
128 alpha value makes the red 50% transparent.Reading diff images
- No visible highlights
- Large red areas
- Small red spots
If a diff image is generated but shows no red highlighting, the SSIM score flagged differences but they’re below the visual threshold (20/255). Consider adjusting
--threshold to be more tolerant.SSIM scores explained
What is SSIM?
The Structural Similarity Index (SSIM) measures perceived image quality difference. Unlike pixel-by-pixel comparison, SSIM considers:- Luminance: Overall brightness
- Contrast: Range of tones
- Structure: Spatial patterns and edges
How the tool uses SSIM
From pdf_visual_diff.py:54:- Converts both pages to numpy arrays
- Computes SSIM across all color channels (
channel_axis=-1) - Uses data range 0-255 for 8-bit RGB images
- Returns a score between 0.0 (completely different) and 1.0 (identical)
SSIM in practice
Threshold decision guide
| Threshold | Use case | Sensitivity |
|---|---|---|
1.0 | Exact match required, catch all changes | Highest |
0.999 | Ignore font rendering variations | High |
0.995 | Tolerate minor PDF generation differences | Medium |
0.99 | Accept small layout shifts | Low |
0.95 | Only flag significant visual changes | Lowest |
Start with the default
1.0 threshold. If you see false positives from rendering variations, gradually lower it to 0.999 or 0.995.Automating result analysis
Python example
Bash example
CI/CD integration
GitHub Actions example
- Runs the comparison with a tolerant threshold
- Checks the results.json status
- Uploads diff images as artifacts if the test fails