Skip to content

Instantly share code, notes, and snippets.

@johnhany97
Created April 23, 2015 00:31
Show Gist options
  • Save johnhany97/2e667d3a54b45b178aad to your computer and use it in GitHub Desktop.
Save johnhany97/2e667d3a54b45b178aad to your computer and use it in GitHub Desktop.
Batch Replace specific text in PDF automatically using pdftk
Create a file with this:
#!/bin/bash
oldtext=$1
newtext=$2
pdffile=$3
cp $pdffile $pdffile.bak
pdftk $pdffile output $pdffile.tmp uncompress
sed -i "s/$oldtext/$newtext/g" $pdffile.tmp
pdftk $pdffile.tmp output $pdffile compress
rm -rf *.bak
rm -rf *.tmp
Then run this command:
for i in *.pdf ; do replacepdftext.sh oldword newword $i ; done
where replacepdftext.sh is the name of the file earlier created
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment