Creating a PDF with ASP
By Ty Button
print this article
email this article to a colleague
Introduction
Adobe's PDF format has become the lingua franca of cross-platform reporting for many agencies and companies. While I was no great fan of the product, I have to admit it probably does a better job of producing a compact document with loads of formatting than Word ever will.
Getting Started
Working for a staffing firm, I have written all of our front-end software to run over the Internet so we can share common databases with our smaller branch offices. The biggest problem we faced, however, was reporting. How do we get live documents (applications, etc.) to generate themselves when an applicant sits down at the kiosk and fills out their on-line employment application? While we're doing a great job of capturing the data, we still need an applicant to sign the application, W-4, etc.
I tried a number of things, but the limits seem to be:
If I could produce it fast, it was an HTML form derivative and looked terrible when printed.
If I could produce it looking right, it was clunky and slow. This is because I settled on RTF as my best initial option and ended up using the File System Object to write RTF files based on a template and parse my info into them. The disk reads and writes took their toll.
Remember, we抮e not talking about tabular data or an Excel spreadsheet. We want the application with our logo to be processed.
Finally, I settled on Adobe. I hate the viewer and wish I didn't have to mess with it. However, the formatting looks good and the files are thin. Most users have it on their system, and all my users do.
So I searched and searched for ways to pass data from HTML forms to PDF files. I tried using Adobe forms, but didn't really like working with the validation, etc., and then would still have to figure out how to incorporate the database calls. This wasn't at all what I wanted. I wanted to pass data directly from my HTML form to a database while generating the field data into the PDF file for display or printing.
Finally, there was a clue on UseNet. A link posted by Jeremy Hunter contained much of what I will address here. http://partners.adobe.com/asn/developer/acrosdk/forms.html
REQUIRED SOFTWARE
ADOBE (the full version) is required on the workstation defining the fields. (Not the server)
This is the link to the Adobe Forms Acrobat Toolkit. From there it was easy going.
Step 1. Download the toolkit and unzip it to your directory of choice.
When you do, you'll find that all the source code is included in VB and C++. We're not going to worry about that here, but the code is there if you need it.
Step 2. Register your dlls.
Two dlls need to be copied to your server. The first is in the Visual Basic sub folder and is named fdfacx.dll. The second is in the Visual C subfolder and is named fdftk.dll. Run refsvr32 on the fdfacx.dll file. It will take care of registering the other itself. I put both in c:\winnt\system32\ and from that directory typed regsvr32 fdftk.dll. If you get an error message, check to make sure both files are really there. If not, we're set to go.
Step 3. Create the form.
We'll use a form everyone is too familiar with for this demonstration - the W-4. This one is readily available on http://www.irs.gov and gives us enough fields to show what we can do.
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<H1>Adobe FDF Example</H1>
<FORM NAME=W4Help ACTION=W4.asp METHOD = POST>
<TABLE>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>First Name</TD>
<TD><INPUT TYPE=TEXT NAME=txtFirstName>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Middle Initial
</TD>
<TD><INPUT TYPE=TEXT NAME=txtMI>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>LastName</TD>
<TD><INPUT TYPE=TEXT NAME=txtLastName>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Social</TD>
<TD><INPUT TYPE=TEXT NAME=txtSocial1 SIZE=3>-
<INPUT TYPE=TEXT NAME=txtSocial2 SIZE=2>-
<INPUT TYPE=TEXT NAME=txtSocial3 SIZE=2></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Street Address</TD>
<TD><INPUT TYPE=TEXT NAME