Skip to main content

A tool for comparing PDF files

Project description

DiffPDF

Build codecov Python 3.10+ License: MIT

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.

Each stage only runs if all previous stages pass.

⚠️ Performance Warning: The Python port of pixelmatch is extremely slow.

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
  -v, --verbose           Increase verbosity (-v for INFO, -vv for DEBUG)
  --save-log              Write log output to log.txt
  --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

Call the CLI from Python:

from diffpdf import main
main(["-vv","foo.pdf", "bar.pdf"])

Development

pip install -e .[dev]
pytest tests/ -v
ruff check .

Acknowledgements

Built with PyMuPDF for PDF parsing and pixelmatch-py (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-0.2.0.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

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

diffpdf-0.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for diffpdf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b5e36934a11cd31847c8ceb6083731a437d620f40c7ea6a102d6ac411531d6d
MD5 b2f7e903a2a8db0fd8cf43faeeead7c1
BLAKE2b-256 330ac97280bf72a261541a93d37a3acaa82cc2417f2aba6c1930b0cf81863333

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffpdf-0.2.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-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for diffpdf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56e3621239f759d3b2f2130e342ad6439093eacfbfb406c04475dd7506f904cb
MD5 191ffdf92cef40dc8493727aae9fefa2
BLAKE2b-256 b2cc4a2d0686e6ce86cafb2925ccc0251215f7c6a00dd664ad1ac6ae698887ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffpdf-0.2.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