Created
January 16, 2024 09:29
-
-
Save gsportelli/e6ccd247d13bfdd06e68e61f9a094ce2 to your computer and use it in GitHub Desktop.
pdfcompare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PDF_1="$1" | |
PDF_2="$2" | |
OUT_FILE="$3" | |
OUT_TMPDIR=$(mktemp -d) | |
cleanup() { | |
rm -rf "$OUT_TMPDIR" | |
} | |
trap 'cleanup' EXIT | |
pdftk "$PDF_1" burst output "$OUT_TMPDIR/file_1-page_%03d.pdf" || exit 1 | |
pdftk "$PDF_2" burst output "$OUT_TMPDIR/file_2-page_%03d.pdf" || exit 1 | |
for f1 in $OUT_TMPDIR/file_1-page_*.pdf; do | |
f2="${f1/file_1-page_/file_2-page_}" | |
f_diff="${f1/file_1-page_/diff-page_}" | |
f_out="${f1/file_1-page_/out-page_}" | |
compare "$f1" "$f2" -quiet -compose src "$f_diff" 2> /dev/null | |
pdftk "$f_diff" background "$f1" output "$f_out" || continue | |
done | |
pdftk "$OUT_TMPDIR"/out-page_*.pdf cat output "$OUT_FILE" || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment