By Ty button
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:winntsystem32 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=txtStreetAddress></TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>City
</TD>
<TD><input TYPE=TEXT name=txtCity></TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>State</TD>
<TD><input TYPE=TEXT name=txtState SIZE=2 MAXLENGTH=2></TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>Zip</TD>
<TD><input TYPE=TEXT name=txtZip SIZE=10></TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>Filing Status</TD>
<TD>
<input TYPE=RAdio name=radFilingStatus VALUE="1">Single
<BR>
<input TYPE=RAdio name=radFilingStatus VALUE="2">MarrIEd
<BR>
<input TYPE=RAdio name=radFilingStatus VALUE="3">
MarrIEd but withholding at the higher single rate.
<BR></TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>Allowances Claimed</TD>
<TD><input TYPE=TEXT name=txtAllowances SIZE=2 MAXLENGTH=2> </TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>Additional amount to withhold (if any)</TD>
<TD><input TYPE=TEXT name=txtAdditional SIZE=2 MAXLENGTH=2>
</TD>
</TR>
<TR>
<TD AliGN=RIGHT VAliGN=top>I want to file Exempt from Withholding
</TD>
<TD><input TYPE=CHECKBox name=chkExempt></TD>
</TR>
</table>
<input TYPE=submit>
</FORM>
</BODY>
</HTML>
Step 4. define the Adobe form fIElds.
Open the document in Adobe Acrobat.
Click the form tool.
Paint your first form fIEld (First name).
As soon as you''ve defined it you are asked to name it. I named mine Firstname. Note that there are several additional formatting options. Other than Font size,I choose to do my valIDation and formatting in my ASP document. As this is just a quick demo,I have opted to skip any valIDation. However,I would handle it on the clIEnt sIDe in my form and any formatting server sIDe in my ASP page before I pass the variables.
Continue with the remaining fIElds,naming each and possibly formatting the Font size or attributes.
Save your work to wherever you want on your Web server.
Step 5. Write the ASP page.
Before you start,realize that there is one main object exposed by the FDF toolkit - "FDFApp.FDFApp." There are many methods exposed,and the manual outlines some other possibilitIEs. We''re mainly concerned with two methods,fdfSetValue and fdfSetfile. Here we go,
<%@ Language=VBScript %>
<% Response.Buffer = true%>
<HTML>
<head>
<Meta name="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%
''
'' RetrIEve the user responses
''
Firstname = Request.form("txtFirstname")
MI = Request.form("txtMI")
Lastname = Request.form("txtLastname")
SS1 = Request.form("txtSocial1")
SS2 = Request.form("txtSocial2")
SS3 = Request.form("txtSocial3")
StreetAddress = Request.form("txtStreetAddress")
City = Request.form("txtCity")
State = Request.form("txtState")
Zip = Request.form("txtZip")
FilingStatus = Request.form("radFilingStatus")
Allowances = Request.form("txtAllowances")
Additional = Request.form("txtAdditional")
Exempt = Request.form("chkExempt")
If Exempt = "on" Then
Exempt = "EXEMPT"
Else
Exempt = ""
End If
''
'' Create an instance of the Object
''
Set FdfAcx = Server.CreateObject("FdfApp.FdfApp")
''
'' Use the fdfApp to Feed the vars
''
Set myFdf = FdfAcx.Fdfcreate
''
'' Stuff the variables
''
myFdf.fdfsetvalue "Firstname",Firstname,false
myFdf.fdfsetvalue "MI",MI,false
myFdf.fdfsetvalue "Lastname",Lastname,false
myFdf.fdfsetvalue "SS1",SS1,false
myFdf.fdfsetvalue "SS2",SS2,false
myFdf.fdfsetvalue "SS3",SS3,false
myFdf.fdfsetvalue "StreetAddress",StreetAddress,false
myFdf.fdfsetvalue "City",City,false
myFdf.fdfsetvalue "State",State,false
myFdf.fdfsetvalue "Zip",Zip,false
If FilingStatus = 1 Then
MyFdf.fdfsetValue "StatusSingle","X",false
End If
If FilingStatus = 2 Then
MyFdf.fdfsetValue "StatusMarrIEd",false
End If
If FilingStatus = 3 Then
MyFdf.fdfsetValue "MarrIEdBut",false
End If
myFdf.fdfsetvalue "Allowances",Allowances,false
myFdf.fdfsetvalue "Additional",Additional,false
myFdf.fdfsetvalue "Exempt",Exempt,false
''
'' Point to your pdf file
''
myFDF.fdfSetfile "http://www.servername.com/workorder/w4.pdf"
Response.ContentType = "text/HTML"
''
'' Save it to a file. If you were going to save the actual file past the point of printing
'' You would want to create a naming convention (perhaps using social in the name)
'' Have to use the physical path so you may need to incorporate Server.mapPath in
'' on this portion.
''
myFDf.FDFSavetofile "C:inetpubwwwrootworkorderCheckThis.fdf"
'' Now put a link to the file on your page.
Response.Write "<a href=http://www.servername.com/workorder/CheckThis.fdf>pdf</A>"
''
'' Close your Objects
''
myfdf.fdfclose
set fdfacx = nothing
%>
Conclusion
Without having to be an expert at FDF or pdf,this is my answer for the moment. The users?guIDe that comes with the toolkit outlines all of the methods and looks like it has many possibilitIEs beyond this rudimentary introduction. As you can see,you Could just as easily add database commands to collect the data and log it to a database.
About the Author
Ty button is employed by Cardinal Services,Inc.,a staffing firm in Oregon. Cardinal Services has been named the #1 Staffing Firm in Southern Oregon for both 1997 and 1998 by Oregon Business Magazine,as well as Oregon''s Fastest Planned Growth Company by the South Coast Business Development Center and U.S. Bank. button is the MIS,but spends the bulk of his time on Web-database development and process automation. He can be reached at mailto:ty@ty-button.com.
以上是内存溢出为你收集整理的用asp生成PDF文件(英文)全部内容,希望文章能够帮你解决用asp生成PDF文件(英文)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)