Question

I've got an existing PDF form that my office has created that has form fields for the user to fill out (electronically) and print. Before passing it to the user I would like to open the existing PDF and populate as much (if not all) of that data using php. I've looked into extensions like TCPDF and FPDI, but I'm unable to confirm that what I want to do is even possible by looking at the examples and documentation. Have any of you done this before?

I did see TCPDF::setFormDefaultProp, which looked promising...

Was it helpful?

Solution

Pdftk has a fill_form command. Since it doesn't have PHP bindings you'll have to install it on your server and invoke it with exec() et al but it's pretty easy. To use it you'll have to generate an FDF file, which Pdftk will do given the generate_fdf command, then plug the desired data into it. You can find some information on FDF files here and some example PHP code here and here. In truth I think you could just put the generated FDF file in your PDF script and, given the right escaping, fill the values like you would in any string, then pipe it back into pdftk fill_form.

OTHER TIPS

You can use a commercial product like SetPDF http://www.setasign.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top