Side by side visual comparision differences for PDF documents
Project description
Visual PDF diff
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:
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 th line:
<policy domain="coder" rights="read | write" pattern="PDF" />
And comment the line:
<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->
Comand 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
1.0 (Unreleased)
- 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
- Diff metadata as well
- Make an overlay fully transparent within the diff zone, and translucent gray in the matching zone
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
File details
Details for the file visualpdfdiff-1.0.tar.gz
.
File metadata
- Download URL: visualpdfdiff-1.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff29fd1cd479d0b9a9c63cf7f56549ea9d7a92647e6c54f84381b43e33d02621 |
|
MD5 | 5685efdbac278cb2feb69b23a1309c6b |
|
BLAKE2b-256 | cd57dba31a33319bef7fbd8abe2c625a8382dc1bd794a2ebcdfeb26728a3a928 |
File details
Details for the file visualpdfdiff-1.0-py3-none-any.whl
.
File metadata
- Download URL: visualpdfdiff-1.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7577f27d2f17da1bd06ab0e73d76029c99bfdf2037045d04152c54724026b99 |
|
MD5 | c439ec887f404920570204a4c6dde845 |
|
BLAKE2b-256 | 8356c6f8db01ca457a13cc481c05353121126ed56bc7241d1dc0671b8c5a2355 |