phpregexpdfpdflibalivepdf

Pattern matching text in the body of a PDF and adding hyperlinks with PHP


The situation is as follows: I have a series of big, fat PDF files, full of imagery and randomly distributed text - these are the sections of a huge promotional pricelist for a vast array of products. What I need is to pattern-match all the catalogue codes in the text of each PDF file and to wrap it with a hyperlink that will point to the respective page in an online store.

So the task is very simple - scan a PDF file for all plain-text 10 digits sequences, and convert those into links whose href is http://something?code=[match].

I would also prefer to put this together in a PHP script if possible, but any language would do. I have a gut feeling that maybe even flash could be an option.

Any ideas? Thanks in advance.

EDIT:

Some answers coming in are teaching me pcre syntax. The problem here is that I need to search and replace in a PDF file. So the problem is twofold. Say we'll do this in PHP:

What do you think? Other languages are also an option.

Thanks.


Solution

  • Replacing text in a PDF is difficult and none of the open source PDF solutions support this capability.

    Apago (www.apago.com) has a developed commercial solution for replacing text in PDF files. It's used by greeting card manufacturer to modify pricing, "MADE IN" text, product numbers, etc.