Find and replace strings in PDF using Perl, Ruby or PHP

Is there a script to replace strings in PDF documents? I can use Perl, Ruby or PHP. If possible the regex would be great.

+2


source to share


2 answers


As part of my open CAM :: PDF in the Perl library, I include a tiny front-end program called changepagestring.pl that does what you ask.

However, it only replaces text contiguous in the PDF syntax. If you switch fonts, size, style, etc. In the middle of a phrase, it will not match. If you are doing any advanced kerning it will not match.



These limitations aside, it is really easy to use and it is simple enough that you can easily fork it and hack it to your needs.

+2


source


In Perl, you can parse the content of your PDF file using PDF :: API2 . Then you can search and replace target strings in the usual way ( s///

) and write the new document back to disk.



0


source







All Articles