Skip to main content

pdf-diff

Finds differences between two PDF documents:

  1. Compares the text layers of two PDF documents and outputs the bounding boxes of changed text in JSON.
  2. Rasterizes the changed pages in the PDFs to a PNG and draws red outlines around changed text.

Example Image Output

The script is written in Python 3, and it relies on the pdftotext program.

Requirements

libxml2 >= 2.7.0, libxslt >= 1.1.23, poppler

Requirements installation for Ubuntu:

sudo apt-get install python3-lxml poppler-utils

Requirements installation for OS X:

brew install libxml2 libxslt poppler

Installation

From PyPI:

pip install pdf-diff

From source:

sudo python3 setup.py install

Running

Turn two PDFs into one large PNG image showing the differences:

pdf-diff before.pdf after.pdf > comparison_output.png

Maintainer Notes

To deploy:

python3 -m pip install --user --upgrade setuptools wheel twine
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*

Function flow diagram

compute_changes
│
├── serialize_pdf (called twice)
│    ├── pdf_to_bboxes
│    ├── mark_eol_hyphens
│    │    └── mark_eol_hyphen
│    └── Processes bounding boxes and text
│
├── perform_diff
│    └── Calls external `fast_diff_match_patch`
│
└── process_hunks
     ├── Iterates through diff hunks
     └── mark_difference (called multiple times)

render_changes
│
├── simplify_changes
├── make_pages_images
│    └── pdftopng (converts PDF pages to images)
├── realign_pages
│    ├── Splits pages into sub-pages
│    └── Adjusts box coordinates
├── draw_red_boxes
│    └── Annotates images with rectangles or lines
└── zealous_crop
     └── Crops the image to reduce unnecessary margins

stack_pages
│
└── Combines processed images into a final output

Metadata

Release files for pdf-diff 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdf-diff 0.9.3
File Size Uploaded
pdf_diff-0.9.3.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdf-diff 0.9.3
File Interpreter ABI Platform
pdf_diff-0.9.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / pdf_diff-0.9.3.tar.gz

Download URL pdf_diff-0.9.3.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b45973a57919f83e1583ff7c9fcfd28711b58a21e585a44e8a45d1084c16ab02
BLAKE2b-256 checksum
How to use checksums
082211cb4e1190380cfeb24c65ea3175b88aa1ca8074b3c94619cfc0e0bee49a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pdf_diff-0.9.3-py3-none-any.whl

Download URL pdf_diff-0.9.3-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a97e6ad396f757a9c2b62fab738b798fa9634a862ef238812dfa01bf713dc5a6
BLAKE2b-256 checksum
How to use checksums
c79a9dc309211ce8481301b13a66aa2468cb9c71d97964b711931b871f7f1210
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.9.3 This release

2 release files

0.9.1

3 release files

0.9.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page