Skip to content
Snippets Groups Projects
Commit abfc0479 authored by Vít Novotný's avatar Vít Novotný
Browse files

The `comparepdf.sh` script no longer relies on bash.

parent 2c578ecb
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#!/bin/sh
# This script visually compares two PDF documents on a page-by-page basis.
# Print an error message and die.
die() {
printf "$1\n" "${@:2}" 1>&2
FORMAT="$1"; shift
printf "$FORMAT\n" "$@" 1>&2
exit 1
}
# Check if a file exist.
exists() {
[[ -e "$1" ]] || die 'File "%s" does not exist.' "$1"
[ -e "$1" ] || die 'File "%s" does not exist.' "$1"
}
# Check that the input files exist.
......@@ -24,20 +25,21 @@ DEST_DIR=`mktemp -d` && trap 'rm -r $SOURCE_DIR $DEST_DIR' EXIT &&
# Compare the individual pages.
DIFFER=false; PAGES=""
while read PAGE; do
if [[ -e $SOURCE_DIR/$PAGE && ! -e $DEST_DIR/$PAGE ]]; then
for PAGE in `((cd $SOURCE_DIR && ls *.pdf) && (cd $DEST_DIR && ls *.pdf)) | sort -u`; do
if [ -e $SOURCE_DIR/$PAGE -a ! -e $DEST_DIR/$PAGE ]; then
die 'The document "%s" does not contain page "%d".' "$1" "${PAGE%%.pdf}"
elif [[ ! -e $SOURCE_DIR/$PAGE && -e $DEST_DIR/$PAGE ]]; then
elif [ ! -e $SOURCE_DIR/$PAGE -a -e $DEST_DIR/$PAGE ]; then
die 'The document "%s" does not contain page "%d".' "$2" "${PAGE%%.pdf}"
else
if ! comparepdf --compare=appearance --verbose=0 $SOURCE_DIR/$PAGE $DEST_DIR/$PAGE; then
DIFFER=true
PAGES="$PAGES ${PAGE%%.pdf}"
PAGES="$PAGES, `echo ${PAGE%%.pdf} | sed 's/^0*//'`"
fi
fi
done < <(((cd $SOURCE_DIR && ls *.pdf) && (cd $DEST_DIR && ls *.pdf)) | sort -u)
done
# Print out the result.
if $DIFFER; then
die 'The documents "%s" and "%s" differ in pages%s.' "$1" "$2" "$PAGES"
PAGES="$(echo "$PAGES" | tail -c+3)"
die 'The documents "%s" and "%s" differ in pages %s.' "$1" "$2" "$PAGES"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment