Parsing XFDF in PHP

A handy snippet of PHP code that can be used to parse XFDF data.
This past week at work I have been working on using Adobe Acrobat to submit form data. The value of this is that the form data can be reimported into the PDF form then printed all purty-lookin’. Anyway, Acrobat allows you to submit your form data in several different formats. One, FDF, is usable in PHP provided you load this module thingy. Unfortunately, the server I want to run the PHP script on uses Irix and the module is unavailable for Irix. Poor.

I then turned to XFDF, which is essentially FDF data all XML-ified. PHP has an XML parser built in, so I don’t have to load any crazy modules to parse the data. Unfortunately, PHP’s parser is SAX-based rather than DOM-based, so it took me a rather long time to figure out how to get it working right. Anyway, here’s the PHP code that essentially takes XFDF data (declare $file as a string pointing to the location of your XFDF file) and parses it into an associative array ($values). The array is indexed by the XFDF field names. The code below is not entirely complete since I snipped it out of a larger file, but if you look at it, I think you’ll get the idea. It’s pretty simple once you figure out the way PHP does XML processing.

View Code

Contributed by: Tyler Butler

2 thoughts on “Parsing XFDF in PHP”

  1. I tried this with standard fields and worked great.
    How would you do this with Hierarchical fields

    Field names in PDF file.
    I’ am guessing some kind of recursion


  2. i too am trying to parse PDF FDF data in PHP. i can find no examples of how to do this…my main question is how to get access to whatever structure acrobat uses to send the FDF data. i had thought this would be in the $_POST array, but it is not there. so where do i find this data???

    help please.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.