#native_company# #native_desc#

FDF Support in PHP Page 4

By Uwe Steinmann
on November 16, 2000

Beside the fact that PDF forms have a nicer appearance than HTML forms, there
seems to be no real advantage of this technology.
However, there is another usage of FDF. You can turn the above process around
and populate a PDF document with data. This is quite useful if you
need to customize only certain parts in a PDF document, e.g. a address,
date etc..
One could also create the complete PDF document, with PHP’s PDF creation
functions, but this is a lot of work for complex documents. In general, it
is also desirable to use prepared documents created
by a designer, for example. Creating PDF forms with the PDF functions in PHP is not
Populating a PDF document with data is quite simple with FDF.
You will have to create a PDF document and add input fields to it, e.g.
with Acrobat 4. Put in on your web server.
Then, you need to create the FDF document with PHP, which contains each
field, its value and a reference to the document where the data
is to be inserted. (The PDF document you have just created). This will
be done on the fly with PHP. The reference is a URL pointing to the PDF
Taking the first example as a basis, the following script shows how easy
this is with PHP. The second part of the script has been added.


   $fdffp fopen("test.fdf""w");



   $fdf fdf_open("test.fdf");

$volume fdf_get_value($fdf"volume");

$date fdf_get_value($fdf"date");

$comment fdf_get_value($fdf"comment");

   if(fdf_get_value($fdf"show_publisher") == "On") {

$publisher fdf_get_value($fdf"publisher");

   } else

$publisher "";

   if(fdf_get_value($fdf"show_preparer") == "On") {

$preparer fdf_get_value($fdf"preparer");

   } else

$preparer "";


   $outfdf fdf_create();














Header("Content-type: application/vnd.fdf");

$fp fopen("outtest.fdf""r");




In this example several steps are performed:
  1. The user fills out the PDF form example2.pdf
  2. After hitting the submit button, the URL associated with the submit
    button is called. In this case, it has to be the PHP script.
  3. The PHP script retrieves the data from the FDF data stream and
    creates a new FDF document, which contains the data for the resulting
    PDF document.
  4. The FDF document is sent back with the MimeType application/vnd.fdf.
  5. The Acrobat Plug-In reads the data and displays the refereed
    PDF document. In this case resultlabel.pdf.
This is still not everything FDF has to offer, but there is too much left
to be discussed in this tutorial. You should check out the
at Adobe’s web site.
— Uwe