How to find and replace text in a existing PDF file with PDFTK (or other command line application)

前端 未结 1 614
太阳男子
太阳男子 2020-12-04 18:20

I have on each page of my PDF document a line with this string:

%REPLACE%

Which I\'d like to find and replace with another string.

Does

相关标签:
1条回答
  • 2020-12-04 19:07

    You can try to modify content of your PDF as follows

    1. Uncompress the text streams of PDF

      pdftk file.pdf output uncompressed.pdf uncompress
      
    2. Use sed to replace your text with another

      sed -e "s/ORIGINALSTRING/NEWSTRING/g" <uncompressed.pdf >modified.pdf
      
    3. If this attempt was successful, re-compress the PDF with pdftk

      pdftk modified.pdf output recompressed.pdf compress
      

    Note: This way is not successful every time, mainly due to font subsetting

    0 讨论(0)
提交回复
热议问题