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
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 image output directory (optional, if not specified no diff images are saved)
-v, --verbose Increase verbosity
--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 images saved)
diffpdf("reference.pdf", "actual.pdf")
# With options (save diff images to ./output directory)
diffpdf("reference.pdf", "actual.pdf", output_dir="./output", threshold=0.2, dpi=150, verbose=True)
Development
pip install -e .[dev]
pytest tests/ -v
ruff check .
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-0.3.2.tar.gz.
File metadata
- Download URL: diffpdf-0.3.2.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
719a4479f1887bf5f4f9054235351d714e1a71273e86020412e59cfa5b031afd
|
|
| MD5 |
6c7e592a017bd00e011617e15efc5daf
|
|
| BLAKE2b-256 |
dfa52bb4eb2ddd89e601c93db732d3172dd2b92c0b325efd7d4b16ae9386d95f
|
Provenance
The following attestation bundles were made for diffpdf-0.3.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-0.3.2.tar.gz -
Subject digest:
719a4479f1887bf5f4f9054235351d714e1a71273e86020412e59cfa5b031afd - Sigstore transparency entry: 787367268
- Sigstore integration time:
-
Permalink:
JustusRijke/DiffPDF@9696865b20998e7cb04bbf406a052a4f1428e30c -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9696865b20998e7cb04bbf406a052a4f1428e30c -
Trigger Event:
release
-
Statement type:
File details
Details for the file diffpdf-0.3.2-py3-none-any.whl.
File metadata
- Download URL: diffpdf-0.3.2-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9172a5176c396dd3f3fc7c0e209a6d8d9e1101dbe032bc9b6d5014c82cfba2c3
|
|
| MD5 |
bbb7c983362b06c503774cdc744deb8c
|
|
| BLAKE2b-256 |
46ca81c683bb8ef27e65b21e106ba36e963186f47f89cf51717ae66cdb11db2e
|
Provenance
The following attestation bundles were made for diffpdf-0.3.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-0.3.2-py3-none-any.whl -
Subject digest:
9172a5176c396dd3f3fc7c0e209a6d8d9e1101dbe032bc9b6d5014c82cfba2c3 - Sigstore transparency entry: 787367275
- Sigstore integration time:
-
Permalink:
JustusRijke/DiffPDF@9696865b20998e7cb04bbf406a052a4f1428e30c -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9696865b20998e7cb04bbf406a052a4f1428e30c -
Trigger Event:
release
-
Statement type: