Question:
I need a Linux-based script to replace text in a PDF document on the fly?
speakeasy
2008-08-17 14:05:37 UTC
I would like to serve customized PDF documents from templates. The templates contain tokens like {firstname} that would be replaced with actual data.

Unfortunately, internal compression in the PDF makes it impossible to write a simple search/replace Perl script. What toolkit or existing script would allow me to do this on a Linux web server?
Three answers:
2008-08-17 14:12:30 UTC
Hmmm... that is tricky. I'm guessing that if you could properly decompress it to a file, you could run a sed substitution that would (hopefully) replace what you need. There is a tiny chance that it would screw up an image or other element, but you could try it. The only hard part would be decompressing it, and I have no idea how you could do that. There must be some sort of PDF library that is used in open source PDF readers and web browsers.
2016-10-17 16:52:32 UTC
Replace Text In Pdf
Scott H
2008-08-18 10:22:21 UTC
This may not be the answer that you are looking for but you could keep your templates in postscript format and perform the search & replace on those files. Then, you could use ps2pdf to convert the postscript file to PDF format for delivery.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...