views:

134

answers:

3

I am looking for some way to code a function (I'm open to any language or library at this point) to take an already existing PDF file as input and return a modified PDF file that links certain words to different URLs. I know PHP and ColdFusion both have good tools for dealing with PDF's, but I haven't been able to find anything that works.

I've been doing this by going through Acrobat and linking the text by hand and was wondering if there was any way to automate the procedure.

Thanks!

A: 

PDFs do support Javascript, perhaps you can create a dummy link in the PDF and have it call a JS function that contains the URL. Then you only need to generate a little bit of JS inside the PDF to change the link.

TravisO
I am not sure I understand the suggestion. How does that avoid them having to edit by hand. I believe they said they were _existing_ pdf's. In which case they would still need to tie that function to each word ..
Leigh
The coder would use this information IN ADDITION to a library the other answers are suggesting. I would assume injection the Javascript into the PDF using a library is much easier than trying to alter the binary data.
TravisO
Yes, a javascript function would probably reduce duplication. But either way they still have to modify _individual_ words to trigger whatever url is linked to each word, which is extremely non-trivial. Given that the pdf format really was not intended for this kind of editing, Sergii's suggestion is probably the closest they are going to get here.
Leigh
+2  A: 

With ColdFusion you can extract the text with DDX (see Extracting text from a PDF document on the page), modify it using search/replace and generate new document.

Sergii
A: 

If I understand what you're trying to do, you should be able to use CFPDF (http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_02.html#2922772) to read the pdf file into a ColdFusion variable, replace whatever content you want in that variable, then save the content back to pdf.

Eric
Pdf's are binary files. So you cannot do a search and replace as you might with a text file.
Leigh
Yes you can, once ColdFusion converts it into a variable.
Eric
Nope. Though you might not receive an error, it does not actually _work_. Try it and see for yourself. Pdf's just do not work that way.
Leigh