Find and replace with on PDF file from command line

I want to find specific text or word from PDF file and replace it with another text and make a new PDF file from command-line. I tried with sed, find, awk series on text files but I want to get on PDF file. Which command line utility will help me?


Solution 1:

Use pdftk to uncompress the file, then edit via sed and finally recompress it.

pdftk input.pdf output uncompressed.pdf uncompress
sed -i 's/foo/bar/g' uncompressed.pdf
# uncompressed.pdf now has all the changes
pdftk uncompressed.pdf output changed.pdf compress

Of course any text in images cannot be changes like this.