Skip to content

Instantly share code, notes, and snippets.

@monkeydom
Created October 12, 2018 07:44
Show Gist options
  • Save monkeydom/2c175141cd9f10062e55cc0d75b47b03 to your computer and use it in GitHub Desktop.
Save monkeydom/2c175141cd9f10062e55cc0d75b47b03 to your computer and use it in GitHub Desktop.
Takes a pdf, removes metadata and generates a deterministic version based on the contents so version control is happy.
#!/bin/sh
TEMP=${1}_tmp
QPDF=${TEMP}_qpdf
cp $1 $TEMP
exiftool -all:all= -overwrite_original_in_place $TEMP
qpdf --deterministic-id --linearize $TEMP $QPDF
perl -pi -ne 's/(\/ID\s*\[<*)([\d+a-fA-F]*)(>\s*<)([\d+a-fA-F]*)(>)/\1\4\3\4\5/g' $QPDF
cp $QPDF $1
rm $QPDF $TEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment