This fortnight I'll provide 2 examples with step-by-step descriptions of how
to populate a PDF file's form fields with data processed by a webserver. One example uses Microsoft's Active Server Pages
(ASP) to populate a PDF form, and the other uses the ActiveX version of the FDF toolkit to populate a PDF form with data
submitted from an HTML form.
Why PDF forms and not HTML forms?
PDF file forms published on the World Wide Web can be
pre-populated by data from a webserver's application or CGI script, much like HTML forms (by dynamically rendering the page
with the VALUE tag populated). However, unlike HTML forms the PDF form's field data can be updated without reloading the page
from the server. When a user submits data to the webserver's application or CGI for processing, only the form data is
updated, not the whole page. The data is updated with a form data format (FDF) unique to PDF files. The FDF data is
considerably smaller than HTML files. As a result, building Internet application that process data using PDF forms can be
much more efficient than HTML forms.
Despite the bandwidth efficiencies FDF data affords the Internet developer, the decision to build Internet forms in PDF
version HTML should be carefully considered. For some guidelines to determine which format is best for your form-based
applications be sure to read (or review) chapter 4 in my book Internet Publishing with Acrobat. You can purchase a
hard-copy at any of the online book stores or view the chapter online here at http://www.imagebiz.com/ipwa.
PDF forms function differently than HTML forms. Here's a sample
of how a PDF form works:
The user triggers the "Submit Form" action from a PDF file object trigger like a submit button, a page action,
a link, etc. Note: the user must be viewing the PDF within a web browser.
The form data is sent to the webserver for processing (or storage and any number of other actions). This data is sent
as either HTML-encoded form data or in the FDF format.
The webserver's application or script takes whatever action appropriate with the data. Depending on the application or
script, the results of the storage or processing can then be sent back to the user.
The data is received from the application or script and the form field's are updated. FDF data can also create fields,
display status dialog boxes, and generate new PDF pages dynamically (using "templates"). These other functions will
be examined in later columns.
How to use FDF form data with a PDF form.
>For this example, you'll build a PDF form using Microsoft's
Active Server Pages (ASP). The form will display the server's current date and time.
Open the PDF file that contains the form you want to use. (For this example you can using an existing PDF file if you
want to construct the PDF form according to the steps in this how-to guide. The complete form can be viewed at the end of
If you're using the example PDF file, add 2 fields with the following names:
Create a submit button with the form tool. In the Field Properties dialog box, click the Actions tab.
From the list, select the "Mouse Down" trigger and click the Add button.
From the Action type select list, choose the "Submit Form" action and click the "Select URL"
In the SubmitForm Selections dialog box, enter the URL of the application that will process the submitted form data. For
this exercise use: "http://www.planetpdf.com/planetpdf /inetpub/demo1.asp"
. If you wish to run the example for your server the URL could look like: http://www.yourserver.com/demo1.asp or
Set the Export Format to HTML Form (URL encoded).
In the field selection sample, leave the default option. The default "All Fields" radio button exports all
names and values of all the fields are the PDF form. This section allows you to select particular fields for submission.
Click Ok to close the SubmitForms Selections dialog box.
In the Add Action dialog box, click Set Action.
In the Field Properties dialog box, click Ok.
Save the file as "demo1.pdf" and upload it to your webserver.
Next, copy the following ASP script and save it on your server as an ASP file. Be sure that the URL set in step 6 points
to the location of this ASP file on your web server. Here's the script:
PDF files can be used to take data submitted by users from HTML
forms and render a page that can be printed by the user. Order forms, tax forms, and sales collateral are all possible
applications for converting HTML form data to a PDF file for presentation.
Building a script to convert the HTML data to a FDF file that opens a PDF file is shown in the next example.
Unfortunately, user must make configure their web browser to properly view the data. If you or your users are viewing PDF
files with Acrobat 4.0, the installer should have made the configuration. If not, to configure your web browser to properly
view FDF data you must select Acrobat as the application that handles the MIME type application/vnd.fdf. Otherwise, your web
browser will try to download the FDF file.
How to configure Netscape (e.g., Communicator 4.x):
Select Preferences > Applications.
Choose Acrobat as the "helper" application.
Uncheck the checkbox "Ask me before opening downloaded files of this type".
How to configure Internet Explorer (for Windows 9x users):
Open Windows Explorer, choose the menu item View > Options > file Types.
Check to make sure there is an entry for Adobe Acrobat Forms Document with the Default Extension for Content Type set to
FDF and the Content Type (MIME): set to "application/vnd.fdf.".
Uncheck the checkbox "Confirm open after download".
Under "Actions:" there should be an entry for "open," and in its properties, "Application used
to perform action" should be set to C:\Program Files\Adobe\Acrobat 4.0\Acrobat\Acrobat.exe (or wherever Acrobat
The checkbox "Use DDE" should be unchecked.
Also, be sure to the file > Preferences > Weblink menu item and choose your browser from within Acrobat.
The data submitted in the HTML form is rendered within the PDF file. Additionally, a status dialog box has been added.
Build your own version of the demo:
Open the blank PDF file in Acrobat.
Create three fields: "nametitle", "address" and "contact". In the example, the appearance
of nametitle is 8 point Bold Helvetica with right justification. "Address" is 8 point Helvetica with right
justification and contact is 8 point Helvetica Bold-Oblique with colored gray text, left justified.
Copy these three fields throughout the business card template. For easy alignment, turn on the snap to grid option.
Select View > Snap to Forms Grid.
Either create the HTML form as used in the example (field names are firstname, middlei, lastname, title, street,
poboxorfloor, city, state, zip, phoneareacode, phoneprefix, phonesuffix, faxareacode, faxprefix, faxsuffix, email, website;
form method= "post") or copy the source of the file for you use.
Here's the source of the ASP file:
<%@ LANGUAGE = VBScript%>
'*** Create the FDF object.
Set FdfAcX = Server.CreateObject("FdfApp.FdfApp")
Set objFdf = FdfAcX.FDFCreate
'*** Set the location of the PDF file you create.
'*** Set the variables with data from the various Request
'*** data name/ value pairs posted from the HTML form. I'm using
'*** rather verbose code here, hopefully to benefit beginners
nametitle = Request.Form("firstname") & " " & Request.Form("middlei") & "
" & Request.Form("lastname") & ", " & Request.Form("title")
address = Request.Form("street") & " " & Request.form("poboxorfloor") & "
" & Request.Form("city") & " " & Request.Form("state") & "
" & Request.Form("zip")
contact = "(" & Request.Form("phoneareacode") & ")
" & Request.Form("phoneprefix") & "-" & Request.Form("phonesuffix") & "
(" & Request.Form("faxareacode") & ") " & Request.Form("faxprefix") & "-"
& Request.Form("faxsuffix") & " " & Request.Form("website") & "
" & Request.Form("email")
'*** Use the FDFSetValue method to the PDF's name/value
'*** where the value is one of the variables set above.
objFdf.FDFSetValue "nametitle", nametitle, Off
objFdf.FDFSetValue "address",address, Off
objFdf.FDFSetValue "contact",contact, Off
'*** Use the FDFSetStatus method to display an alert status box.
objFdf.FDFSetStatus "Your business cards have been created."
'*** Write the data back to the buffer stream.
Response.ContentType = "application/vnd.fdf"
'*** Close the object and clean-up.
Set objFdf = Nothing
Set FdfAcX = Nothing
These two working examples should give you the basics on how to build
a PDF form with either ASP or the ActiveX toolkit. As the ActiveX toolkit has much more functionality not covered in these examples, I plan to cover more of the FDF toolkit next month.
If you've got questions, I'll do my best to answer them. Please let me know what you think of this column and how I can improve it. As always, I'm available to consult on projects big and small. Contact me at email@example.com.
OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.