Skip to main content

A tool for comparing PDF files

Project description

DiffPDF

Build codecov Python 3.10+ License: MIT PyPI - Version PyPI - Downloads

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:

  1. Hash Check - SHA-256 comparison. If identical, exit immediately with pass.
  2. Page Count - Verify both PDFs have the same number of pages.
  3. Text Content - Extract and compare text from all pages (ignoring whitespace).
  4. Visual Check - Render pages to images and compare using pixelmatch-fast.

Each stage only runs if all previous stages pass.

Installation

Install Python (v3.10 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
  --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)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffpdf-1.1.0.tar.gz (102.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffpdf-1.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file diffpdf-1.1.0.tar.gz.

File metadata

  • Download URL: diffpdf-1.1.0.tar.gz
  • Upload date:
  • Size: 102.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diffpdf-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3118e511dff1a116e957736d25e8a4edc6802dfeccaa56b8c200c4ac785ed722
MD5 9b686ea222e0b9f916e7ce7da34ef2f9
BLAKE2b-256 e05aff9a74cd89c6f526af1c81dcc18819e1d02398667de6b30a35815ef64cd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffpdf-1.1.0.tar.gz:

Publisher: pypi-publish.yml on JustusRijke/DiffPDF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diffpdf-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: diffpdf-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diffpdf-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aebe53d3cdf1f8bf20ddbdfeb0a767bc40599827ca2384aeba3540a75d7cdc3
MD5 0cfcaee4d89f228cb799a228e6d239ab
BLAKE2b-256 a8e506fa0ac9b8af56426c4e412b68dc6017755a3cb43626712f0321d98f44ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffpdf-1.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on JustusRijke/DiffPDF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page