Sunday, November 19, 2023

Comparing PDFs, Round 2

I've found an even better application for the idea mentioned in my last post. It can be very hard to see all the copy editor's corrections. Well, PDF comparison to the rescue! This script is slightly more complex, since I have a number of different files from them, one for each chapter. But not a problem. First, explode the PDFs into images using pdftocairo, as before. Now:

#!/bin/bash

#DEBUG=echo;
# basename of the images for this
# chapter from copy editor
TYP=$1;
# basename for 'original' pages
BASE=
SenseBook-19-IX-2023-Revised
# first page number of 'original' pages
XPAGE=$2;

for PG in $TYP*tif; do
    NEXT=$XPAGE;
    if (($XPAGE < 10)); then NEXT=0$NEXT; fi
    if (($XPAGE < 100)); then NEXT=0$NEXT; fi
    $DEBUG compare $PG $BASE-$NEXT.tif Comp-$NEXT.tif;
    XPAGE=$(($XPAGE + 1));
done

When that's done, it gives me the comparison images for that chapter. So now just:

convert Comp*tif Edited-ChN.pdf

And now it's easy to see where the corrections are:



No comments:

Post a Comment

Comments welcome, but they are expected to be civil.
Please don't bother spamming me. I'm only going to delete it.