views:

163

answers:

2

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!

A: 

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.

ire_and_curses
Care to elaborate? I've searched through CPAN documentation of PDF::API2 module but found nothing concerning substitution.Thanks.
Damir Horvat
+2  A: 

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.

Chris Dolan
nice work! I hope these limitation will be removed in its next version. :)
santosh
@santosh not likely. Those limitations have existed since CAM::PDF 0.01 and are unlikely to ever change. It's too hard a problem to solve in my spare time and nobody has been willing to fund the work to date.
Chris Dolan