#! /bin/bash # Usage: $0 file1.pdf file2.pdf # # compares file1.pdf and file2.pdf by rendering each page and using # the 'compare' ImageMagick utility # # Copyright 2007-2014 Sanjoy Mahajan. Licensed under the GNU GPL version 3 # or (at your option) any later version. # # HISTORY # 2014-06-22: Use mudraw instead of pdftoppm. GPL v3+ # 2009-09-30: Fix capture of dB output; don't use a viewer; use pdftoppm # 2007-01-15: First version # if [ -z "$DPI" ]; then DPI=72 fi ext=png if [ -z "$1" -o -z "$2" ]; then echo "Usage: $0 file1.pdf file2.pdf" exit 3 fi # generate the many page images in a temporary directory d=`mktemp -d` mkdir -p $d/a $d/b mudraw -r $DPI -g -o $d/a/%03d.$ext $1 mudraw -r $DPI -g -o $d/b/%03d.$ext $2 wait # find the union of the page numbers (in case one pdf has more pages) pages=`ls $d/{a,b}/*.$ext | sed "s%.*/\([0-9][0-9]*\).$ext%\1%" | sort -un` # compare each page for p in $pages ; do if ! [ -e "$d/a/$p.$ext" ] ; then echo "$p: missing from $1" continue fi if ! [ -e "$d/b/$p.$ext" ] ; then echo "$p: missing from $2" continue fi echo -n "$d/diff-$p.$ext $p " compare -metric mae $d/{a,b}/$p.$ext $d/diff-$p.$ext 2>&1 done