sss: save some space, picture compressor pdfdiff : perform a visual diff on simila pdfs to highlight
39 lines
1.0 KiB
Bash
39 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
# pdfdiff : perform a graphical diff on two similar pdf files, and highlight the differences
|
|
# Usage : pdfdiff SOURCE1 SOURCE2 [OUTPUT]
|
|
#
|
|
# Dependencies: mutool (https://mupdf.com) ; ImageMagikc (imagemagick.org)
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
cp "${1}" "${tmpdir}/a.pdf"
|
|
cp "${2}" "${tmpdir}/b.pdf"
|
|
|
|
cd "${tmpdir}"
|
|
|
|
n=$(mutool info a.pdf | grep -im1 "Pages: " | cut -d " " -f 2)
|
|
m=$(mutool info b.pdf | grep -im1 "Pages: " | cut -d " " -f 2)
|
|
|
|
if test "${n}" != "${m}" ; then
|
|
read -p "Warning: Source PDFs do not have the same number of pages. Continue ? [Y/n]"
|
|
test "${REPLY}" = "n" || test "${REPLY}" = "N" && exit 0
|
|
test "${n}" -gt "${m}" && n="${m}"
|
|
fi
|
|
|
|
mutool draw -F png -A 0 -N -o a-%d.png a.pdf
|
|
mutool draw -F png -A 0 -N -o b-%d.png b.pdf
|
|
|
|
for i in $(seq 1 "${n}") ; do
|
|
compare "a-${i}.png" "b-${i}.png" -compose src "diff-${i}.png"
|
|
montage "a-${i}.png" "diff-${i}.png" "b-${i}.png" -tile 3x1 -geometry +0+0 "out-${i}.png"
|
|
done
|
|
|
|
convert $(ls -v out*.png) out.pdf
|
|
|
|
cd -
|
|
mv "${tmpdir}/out.pdf" "${3:-./diff.pdf}"
|
|
|
|
rm -rf "${tmpdir}"
|