One of our clients has a simple enough request. They wanted a PDF form to be populated in with a set of values gathered from a web form. We decided to settle on xfdf as a method to do this.
I wasn't familiar with xfdf, but was pleased to discover it is an easy format.
<?xml version="1.0" encoding="UTF-8"?> <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"> <fields> <field name="firstname"> <value>Dan</value> </field> <field name="lastname"> <value>Cocos</value> </field> <field name="email"> <value>email@example.com</value> </field> </fields> <f href="example.pdf"/> </xfdf>
Now that the xfdf problem was solved we had to move on next to adding the fields to the PDF. We were unable to find suitable PHP libraries to handle it. Luckily there is a free and open source Java* library iText that does all of this and more.
Miles an EchoDitto intern took the first crack at it and had a working example in no time. A little bit of code clean up and voila a short while later a working tool to merge form data into a PDF.
*There is also a C# port for those so inclined.