Diff-pdf: tool to visually compare two PDFs
41–50 of 85 posts
Re: Diff-pdf: tool to visually compare two PDFs
#42I have been using this in a CI pipeline to maintain a business-critical PDF generation (healthcare) app (started circa 2010 I think), here is the RSpec helpers I'm using: https://gist.github.com/thbar/d1ce2afef68bf6089aeae8d9ddc05d... The code contains git-stored reference PDFs, and the test suite re-generate them and assert that nothing has changed. Helped a lot to audit visual changes, or PDF library upgrades!
could you not just compare the source (or perhaps even the hash) of the PDF and assert on that?
A number of the financial and medical institutions I deal with re-generate PDFs every time you request them, but the content is 99-100% identical. Sometimes just a date changes. So I use a perceptual hash and content comparison to automate detecting truly new documents vs. ones that are only slightly changed.
Re: Diff-pdf: tool to visually compare two PDFs
#43ImageMagick can do a visual PDF compare:
magick compare -density "$DENSITY" -background white "$1[0]" "$2[0]" "$TMP"
(density = 100, $1 and $2 are the filenames to compare, $TMP the output file)You need to do some work to support multiple pages, so I use this script:
https://gist.github.com/mbafford/7e6f3bef20fc220f68e467589bb...
This also uses `imgcat` to show the difference directly in the terminal.
You can also use ImageMagick get a perceptual hash difference using something like:
convert -metric phash "$1" null: "$2" -compose Difference -layers composite -format '%[fx:mean]\n' info:
I use the fact you can configure git to use custom diff tools and take advantage of this with the following in my .gitconfig: [diff "pdf"]
command = ~/bin/git-diff-pdf
And in my .gitattributes I enable the above with: *.pdf binary diff=pdf
~/bin/git-diff-pdf does a diff of the output of `pdftotext -layout` (from poppler) and also runs pdf-compare-phash.To use this custom diff with `git show`, you need to add an extra argument (`git show --ext-diff`), but it uses it automatically if running `git diff`.
Re: Diff-pdf: tool to visually compare two PDFs
#44Re: Diff-pdf: tool to visually compare two PDFs
#45In a previous job, I had to validate the output of an unreliable production publishing system, so I tested dozens of PDF comparison tools available at the time. The best I found was called Delta Walker. It was proprietary commercial Mac-only software, but reasonably inexpensive, accurate, and could handle long PDFs with lots of graphics well. I remember evaluating this diff-pdf tool and finding that it fell short in…
Re: Diff-pdf: tool to visually compare two PDFs
#46I rely heavily on PDF comparison via PDF-XChange Editor, which is accurate for text, but often has trouble highlighting visual changes correctly.
Re: Diff-pdf: tool to visually compare two PDFs
#47You can do this with Beyond Compare (it's not free, but not very expensive either) https://www.scootersoftware.com/
Beyond Compare is one of those priceless tools I pay for myself instead of waiting for my employer to pay for it. Price/functionality wise it's worth its weight in gold, it's cross platform, and its licensing is very liberal. There's just no FOSS compare tools out there that can match BC.
I'm genuinely curious - I heard of lot of BC being 'the tool' for diffing. I'm used to Meld, but my current employee has a pretty strict policy which tools could be used so at some point I've managed a licence for some older version of BC. But for some reason I've found its UI/the way it works a bit less optimal that I was accustomed for. Since I'm using that primarily for text diffs these day I usually use a diff tool from IntelliJ Idea (I have Idea open all the time).
Re: Diff-pdf: tool to visually compare two PDFs
#48Re: Diff-pdf: tool to visually compare two PDFs
#49Related - this might be helpful to someone. ImageMagick can do a visual PDF compare: magick compare -density "$DENSITY" -background white "$1[0]" "$2[0]" "$TMP" (density = 100, $1 and $2 are the filenames to compare, $TMP the output file) You need to do some work to support multiple pages, so I use this script: https://gist.github.com/mbafford/7e6f3bef20fc220f68e467589bb... This also uses `imgcat` to show the differe…
I'm still blown away how powerful imagemagick is after using it for a decade or two, what an inspiring piece of open source software.
Re: Diff-pdf: tool to visually compare two PDFs
#50Can anyone recommend a method to deduplicate pdfs? The hash is often different but the content and meta data is 99.99% the same.
exiftool -all= -o ${filename}.stripped.pdf ${filename}.pdf
That won't help you with small differences in the contents, but might help with small differences in metadata. Running `md5sum` on the stripped PDF should give more reliable dedupe results.I was recently working on a similar problem for JPG, RAW, and MP4 files (photo/video backup) so it is fresh in my mind.