Ubuntu: find and replace with on pdf file from command line


in linux,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 help me?.thanks in advance.


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  #uncopressed.pdf now has all the changes  pdftk uncopressed.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!

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »