Skip to main content

Visual PDF diff

CI Status Coverage Status PyPi PyPI - Downloads PyPI - Python Version

Visual side by side comparision of rendered PDF documents.

You can use this in several ways:

  • a commandline tool to obtain the diff of two pdfs
  • a Python function to do the same from other Python programs
  • an equality assertion to be used in python-unittest
  • a back-to-back assertion to be used in python-unittest
  • an extension for the tool back2back to make back-to-back tests of the PDF outputs of your commands

The generated diff looks like this:

Diff output example

Installation

sudo apt install imagemagick # Or the equivalent if not debian based
pip install visualpdfdiff
pip install b2btest # if you want to use the back2back command

NOTE: visualpdfdiff requires enabling ImageMagick to handle PDF. This is disabled by default for security reasons. If you are running a web server accepting PDF files from outside, please, consider the security implications.

Edit /etc/ImageMagick-*/policy.xml and uncomment the line:

<policy domain="coder" rights="read | write" pattern="PDF" />

And comment the line:

<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->

Command line diff tool

visualpdfdiff a.pdf b.pdf [output-diff.pdf]

Returns 0 if both pdfs are raster equal, -1 if they are not.

If an output is provided the side-by-side diff pdf is generated. Not providing an output is faster when diff exists, though, so checking and then generating is faster when you expect, being equal most of the time.

Python diff function

from visualpdfdiff import diff

haveDifferences = diff('a.pdf', 'b.pdf', 'out.pdf')

Unittest back-to-back assertion

Compares against the last validated output. If the extension is PDF, visualpdfdiff will be chosen to detect and output the differences.

class MyClass_Test(unittest.TestCase):

	from b2btest import assertB2BEqual

	def test_otherMethod_conditions(self):
		...
		self.assertB2BEqual('b.pdf')

Command back2back tests

Using the back2back command. Also, by installing this package, PDF outputs are compared using visualpdfdiff.

myTest:
  command: ./myreportscript.py -o output.pdf
  outputs:
  - output.pdf

Similar tools

  • pdfdiff: Extracts text and diff that, then draws an outline on the text. Better for text diffing, but not so for layout diffing.
  • qtrac's diffpdf: A quite nice (qt-based) graphical tool that does both text and visual diffing. Is not maintained anymore since the authors moved to a close source license.
  • vslavik's diff-pdf:
  • diff-pdf-visualy Quite similar to this one, not just in name, but does not generate an output pdf

CHANGES

2.0.2 (2026-08-04)

  • 💥 diff subpackage is now implementation and should not be used directly
  • 🐛 public symbols available at top level package, as documented
  • ✨ circle kernel
  • 🐛 removed debug print
  • 🎨 black style applied

2.0.1 (2026-08-03)

  • 🏗️ Distribution fixes

2.0 (2026-08-03)

  • 🏗️ Dropped Python 2
  • ♻️ Dependencies modernized (PyPdf2 -> pypdf)
  • ✨ Colored backdrop for unchanged regions

1.0 (2022-06-14)

  • 🏗️ First version as independent module
  • 📝 Previous versions were part of somenergia-oomakotest a test suite to compare outputs of mako reports generated by odoo

TODO

  • Raster resolution configurable by keywords
  • Configurable overlay backdrop color
  • Configurable overlay border width
  • Diff metadata as well
  • Make an overlay fully transparent within the diff zone, and translucent gray in the matching zone

Metadata

Release files for visualpdfdiff 2.0.2

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

Source distribution (sdist)

Source distribution for visualpdfdiff 2.0.2
File Size Uploaded
visualpdfdiff-2.0.2.tar.gz 23.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for visualpdfdiff 2.0.2
File Interpreter ABI Platform
visualpdfdiff-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 46.4 kB

Release files / visualpdfdiff-2.0.2.tar.gz

Download URL visualpdfdiff-2.0.2.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
aa0d6e4bef1336ab3eb3dd354f8802de9b99f5da602aa21c6e144f715fce36b8
BLAKE2b-256 checksum
How to use checksums
a3ec3f82715875ebd5eddc47ef4f84d50c48c0a770a15b4c053057d66c66430d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / visualpdfdiff-2.0.2-py3-none-any.whl

Download URL visualpdfdiff-2.0.2-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f54c82b369b8f9098665e86fdf7da8a96c976f95d8c6182d92957dd8482f026
BLAKE2b-256 checksum
How to use checksums
9984b37b0fb7afaca93ee13e1859b3b72977831e455ab0a34e2880d49cf2e3e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0

2 release files

1.0

2 release files

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