Skip to content

Instantly share code, notes, and snippets.

@dettmering
Last active January 25, 2019 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dettmering/900a3cbcf5ab8d5a65218b1b3be7af9f to your computer and use it in GitHub Desktop.
Save dettmering/900a3cbcf5ab8d5a65218b1b3be7af9f to your computer and use it in GitHub Desktop.
Compare a single page of two PDF files.
#!/bin/bash
FILE_A=$1
FILE_B=$2
PAGE_COUNT_A=$(pdfinfo $FILE_A | grep Pages | awk '{print $2}')
PAGE_COUNT_B=$(pdfinfo $FILE_B | grep Pages | awk '{print $2}')
if [ $PAGE_COUNT_A -eq $PAGE_COUNT_B ];
then
for i in $(seq 0 $PAGE_COUNT_A); do
echo Comparing page $i
convert -density 300 $FILE_A[$i] -transparent white -colorspace RGB -alpha extract -threshold 0 -fill red +opaque black -transparent black A.png
convert -density 300 $FILE_B[$i] -transparent white -colorspace RGB -alpha extract -threshold 0 -fill blue +opaque black -transparent black B.png
composite -blend 50 A.png B.png diff_$i.png
rm A.png B.png
done
else
echo Page count of the documents does not match.
exit 1
fi
#!/bin/bash
FILE_A=$1
FILE_B=$2
convert -density 300 $FILE_A -transparent white -colorspace RGB -alpha extract -threshold 0 -fill red +opaque black -transparent black A.png
convert -density 300 $FILE_B -transparent white -colorspace RGB -alpha extract -threshold 0 -fill blue +opaque black -transparent black B.png
composite -blend 50 A.png B.png diff.png
rm A.png B.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment