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
awk series on text files but I want to get on PDF file. Which command line utility will help me?
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.
A possible solution could look like this...
You can convert pdf files to pure text files by using a couple of tools from the poppler-utils package.
It can be installed via:
sudo apt-get install poppler-utils
Convert pdf file to text file
pdftotext /home/USER/Desktop/test.pdf /home/USER/Desktop/test.txt
Now you're able to do the editing and replacing on your pdf file.
After that you can convert it back by using a package called cups-pdf OR text2pdf.
Might be not the perfect solution, but should do its work.
Hope this helps!