A tool for comparing PDF files
Project description
DiffPDF
CLI tool for detecting structural, textual, and visual differences between PDF files, for use in automatic regression tests.
How It Works
DiffPDF uses a fail-fast sequential pipeline to compare PDFs:
- Hash Check - SHA-256 comparison. If identical, exit immediately with pass.
- Page Count - Verify both PDFs have the same number of pages.
- Text Content - Extract and compare text from all pages (ignoring whitespace).
- Visual Check - Render pages to images and compare using pixelmatch-fast.
Each stage only runs if all previous stages pass.
Installation
Install Python (v3.11 or higher) and install the package:
pip install diffpdf
CLI Usage
Usage: diffpdf [OPTIONS] REFERENCE ACTUAL
Compare two PDF files for structural, textual, and visual differences.
Options:
--threshold FLOAT Pixelmatch threshold (0.0-1.0)
--dpi INTEGER Render resolution
--output-dir DIRECTORY Diff output directory (saves text diffs and visual diff images on failure)
-v, --verbose Increase verbosity
--skip-compare-text Skip text content comparison
--version Show the version and exit.
--help Show this message and exit.
Exit Codes
0— Pass (PDFs are equivalent)1— Fail (differences detected)2— Error (invalid input or processing error)
Library Usage
from diffpdf import diffpdf
# Basic usage (no diff output saved)
diffpdf("reference.pdf", "actual.pdf")
# With options (save text diffs and visual diff images to ./output directory)
diffpdf("reference.pdf", "actual.pdf", output_dir="./output", dpi=300)
Cross-Platform Considerations
PDF rendering may differ slightly between platforms due to different font rendering engines (ClearType on Windows, FreeType on Linux). DiffPDF's default threshold accounts for these minor differences.
Tip: Generate reference PDFs on the same platform as your CI environment
Development
Install uv. Then, install dependencies & activate the automatically generated virtual environment:
uv sync --locked
source .venv/bin/activate
Skip --locked to use the newest dependencies (this might modify uv.lock)
Testing
Run tests:
pytest
Quality Assurance (QA)
Automatically run code quality checks before every commit using pre-commit:
pre-commit install
This installs git hooks that run ruff, type checks, and other checks before each commit. You can run manually at any time with:
pre-commit run --all-files
Acknowledgements
Built with PyMuPDF for PDF parsing and pixelmatch-fast (Python port of pixelmatch) for visual comparison.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diffpdf-1.2.2.tar.gz.
File metadata
- Download URL: diffpdf-1.2.2.tar.gz
- Upload date:
- Size: 127.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da4b1bc737469fffb46c0a573c9156fe8659b2810004b11b5ba084a369de513a
|
|
| MD5 |
98345a88ee8d9da7bfa307e769075288
|
|
| BLAKE2b-256 |
7901006ae77ee5d2113c165c33583b13dc55a88c67b0ebe849f4189ed92945fa
|
Provenance
The following attestation bundles were made for diffpdf-1.2.2.tar.gz:
Publisher:
pypi-publish.yml on JustusRijke/DiffPDF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diffpdf-1.2.2.tar.gz -
Subject digest:
da4b1bc737469fffb46c0a573c9156fe8659b2810004b11b5ba084a369de513a - Sigstore transparency entry: 1262461735
- Sigstore integration time:
-
Permalink:
JustusRijke/DiffPDF@5a135d016d5e3b91cc16af159dd750c545695f53 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5a135d016d5e3b91cc16af159dd750c545695f53 -
Trigger Event:
release
-
Statement type:
File details
Details for the file diffpdf-1.2.2-py3-none-any.whl.
File metadata
- Download URL: diffpdf-1.2.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5660c7171b425dddaa8f1df1bb4de97a2b9675e7d2d0ff13cb532c286f32ea11
|
|
| MD5 |
17b6dda2f2aecc207ef724bcfac5759c
|
|
| BLAKE2b-256 |
3c943271c55d229601177e163547a6fa651ab5a13e49e37dcdb41c7ea5814ad6
|
Provenance
The following attestation bundles were made for diffpdf-1.2.2-py3-none-any.whl:
Publisher:
pypi-publish.yml on JustusRijke/DiffPDF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diffpdf-1.2.2-py3-none-any.whl -
Subject digest:
5660c7171b425dddaa8f1df1bb4de97a2b9675e7d2d0ff13cb532c286f32ea11 - Sigstore transparency entry: 1262461746
- Sigstore integration time:
-
Permalink:
JustusRijke/DiffPDF@5a135d016d5e3b91cc16af159dd750c545695f53 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5a135d016d5e3b91cc16af159dd750c545695f53 -
Trigger Event:
release
-
Statement type: