Hi!
I'm looking for a way to script replacing strings in PDF documents. I can use either perl, ruby or php. If possible, regex would be a blast...
Thank you!
Hi!
I'm looking for a way to script replacing strings in PDF documents. I can use either perl, ruby or php. If possible, regex would be a blast...
Thank you!
In Perl, you can parse the contents of your PDF using the PDF::API2 module. You should then be able to search and replace your target strings in the usual way (s///
), and write the new document back to disk.
As part of my open-source CAM::PDF Perl library, I include a tiny front-end program called changepagestring.pl which does what you ask.
However, it only replaces text that's contiguous in the PDF syntax. If you switch fonts, size, style, etc. mid-phrase then it won't match. If you do any advanced kerning then it won't match.
Those limitations aside, it's really easy to use and it's simple enough that you can easily fork it and hack it to your needs.