用asp產生PDF檔案

來源:互聯網
上載者:User
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



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.