XVII. Forms Data Format functions

Forms Data Format (FDF) is a format for handling forms within PDF documents. You should read the documentation at http://partners.adobe.com/asn/developer/acrosdk/forms.html for more information on what FDF is and how it is used in general.

Note: Currently Adobe only provides a libc5 compatible version for Linux. Tests with glibc2 resulted in a segmentation fault. If somebody is able to make it work, please comment on this page.

Note: If you run into problems configuring php with fdftk support, check whether the header file FdfTk.h and the library libFdfTk.so are at the right place. They should be in fdftk-dir/include and fdftk-dir/lib. This will not be the case if you just unpack the FdfTk distribution.

The general idea of FDF is similar to HTML forms. The diffence is basically the format how filled in data is transmitted to the server when the submit button is pressed (this is actually the Form Data Format) and the format of the form itself (which is the Portable Document Format, PDF). Processing the FDF data is one of the features provided by the fdf functions. But there is more. One may as well take an existing PDF form and populated the input fields with data without modifying the form itself. In such a case one would create a FDF document (fdf_create()) set the values of each input field (fdf_set_value()) and associate it with a PDF form (fdf_set_file()). Finally it has to be sent to the browser with MimeType application/vnd.fdf. The Acrobat reader plugin of your browser recognizes the MimeType, reads the associated PDF form and fills in the data from the FDF document.

The following examples shows just the evaluation of form data.

Example 1. Evaluating a FDF document

  1 
  2 <?php
  3 // Save the FDF data into a temp file
  4 $fdffp = fopen("test.fdf", "w");
  5 fwrite($fdffp, $HTTP_FDF_DATA, strlen($HTTP_FDF_DATA));
  6 fclose($fdffp);
  7 
  8 // Open temp file and evaluate data
  9 // The pdf form contained several input text fields with the names
 10 // volume, date, comment, publisher, preparer, and two checkboxes
 11 // show_publisher and show_preparer.
 12 $fdf = fdf_open("test.fdf");
 13 $volume = fdf_get_value($fdf, "volume");
 14 echo "The volume field has the value '<B>$volume</B>'<BR>";
 15 
 16 $date = fdf_get_value($fdf, "date");
 17 echo "The date field has the value '<B>$date</B>'<BR>";
 18 
 19 $comment = fdf_get_value($fdf, "comment");
 20 echo "The comment field has the value '<B>$comment</B>'<BR>";
 21 
 22 if(fdf_get_value($fdf, "show_publisher") == "On") {
 23   $publisher = fdf_get_value($fdf, "publisher");
 24   echo "The publisher field has the value '<B>$publisher</B>'<BR>";
 25 } else
 26   echo "Publisher shall not be shown.<BR>";
 27 
 28 if(fdf_get_value($fdf, "show_preparer") == "On") {
 29   $preparer = fdf_get_value($fdf, "preparer");
 30   echo "The preparer field has the value '<B>$preparer</B>'<BR>";
 31 } else
 32   echo "Preparer shall not be shown.<BR>";
 33 fdf_close($fdf);
 34 ?>
 35      
Table of Contents
fdf_open — Open a FDF document
fdf_close — Close an FDF document
fdf_create — Create a new FDF document
fdf_save — Save a FDF document
fdf_get_value — Get the value of a field
fdf_set_value — Set the value of a field
fdf_next_field_name — Get the next field name
fdf_set_ap — Set the appearance of a field
fdf_set_status — Set the value of the /STATUS key
fdf_get_status — Get the value of the /STATUS key
fdf_set_file — Set the value of the /F key
fdf_get_file — Get the value of the /F key