Skip to content

Instantly share code, notes, and snippets.

@mpg mpg/pdfdiff.sh

Created Oct 15, 2012
Embed
What would you like to do?
diff of multipage pdfs using imagemagick and pdftk
#!/bin/bash
# visual diff of two pdfs
#
# inspired by:
# http://usakuv.blogspot.fr/2011/05/visual-diff-for-pdf-files.html
# https://docs.google.com/document/pub?id=10GBd9u4e-NwNCd-4t4hb9rcdKJlFFhkkq-b_ezzg73c
print_help() {
echo "Usage: $0 a.pdf b.pdf diff.pdf" >&2
}
baseWD=`date +%s`"diff-PDF-work-dir"
WD="$PWD/$baseWD"
if [ $# = 3 ]; then
if [ -f "$1" -a -r "$1" -a -f "$2" -a -r "$2" -a -w "$PWD" ]; then
if mkdir "$WD"; then
ln -s `readlink -f "$1"` "$WD/1.pdf"
ln -s `readlink -f "$2"` "$WD/2.pdf"
pushd "$WD" >/dev/null
pdftk 1.pdf burst output a%08d.pdf
rm doc_data.txt
pdftk 2.pdf burst output b%08d.pdf
rm doc_data.txt
if [ -e a00000001.pdf ]; then
for aFile in a????????.pdf; do
bFile=`echo $aFile | sed 's/a/b/'`
cFile=`echo $aFile | sed 's/a/c/'`
if [ -e $bFile ]; then
compare $aFile $bFile $cFile
fi
done
pdftk c????????.pdf cat output 3.pdf
fi
popd >/dev/null
mv "$WD/3.pdf" "$3"
rm -rf "$WD"
else
echo "Could not create the working directory $baseWD." >&2
exit 3;
fi
else
echo "Permission error." >&2
exit 2;
fi
else
print_help;
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.