ColdFusion 9.0 Resources |
Applying a watermark to a form created in AcrobatThe following example shows how to prefill an interactive Acrobat tax form and apply a text-string watermark to the completed form that the user posted. Specifically, this example shows how to perform the following tasks:
Note: This example uses the cfdocexamples database
and the 1040 and 1040ez Federal tax forms. A valid user name is
“cpeterson.” To download the 1040 and 1040ez IRS tax forms used
in this example, go to the IRS website. Open the forms in Acrobat (not
LiveCycle Designer) and add a submit button that points to the URL
for the ColdFusion processing page. Also, add a hidden field with
a variable that contains a unique filename used for the completed
tax form.
The first ColdFusion page creates a login form that prompts for the user name and Social Security Number: <!--- The following code creates a simple form for entering a user name and password. The code does not include password verification. ---> <h3>Tax Login Form</h3> <p>Please enter your user name and your social security number.</p> <cfform name="loginform" action="TaxFile2.cfm" method="post"> <table> <tr> <td>User name:</td> <td><cfinput type="text" name="username" required="yes" message="A user name is required."></td> </tr> <tr> <td>SSN#:</td> <td><cfinput type="text" name="SS1" maxLength="3" size="3" required="yes" mask="999"> - <cfinput type="text" name="SS2" maxLength="2" size="2" required="yes" mask="99"> - <cfinput type="text" name="SS3" maxLength="4" size="4" required="yes" mask="9999"></td> </tr> </table> <br/> <cfinput type="submit" name="submit" value="Submit"> </cfform> The second ColdFusion page retrieves the user information from the cfdocexamples database. Also, it creates a pop-up menu with a list of available tax forms: <!--- The following code retrieves all of the employee information for the user name entered on the login page. ---> <cfquery name="getEmpInfo" datasource="cfdocexamples"> SELECT * FROM EMPLOYEES WHERE EMAIL = <cfqueryparam value="#FORM.username#"> </cfquery> <h3>Choose a tax form</h3> <p>Hello <cfoutput>#getEmpInfo.firstname#</cfoutput>,</p> <p>Please choose a tax form from the list:</p> <!--- Create a pop-up menu with a list of tax forms. ---> <cfset thisPath=ExpandPath(".")> <!--- Create a variable called filerID that is a combination of the username and the last three digits of the Social Security number. ---> <cfset filerID="#form.username#_#form.SS3#"> <cfdirectory action="list" name="taxForms" directory="#thisPath#/taxforms"> <cfform name="taxList" method="post" action="TaxFile3.cfm"> <cfselect query="taxForms" value="name" size="10" required="yes" multiple="no" name="myTaxForm"/> <br/><br/> <cfinput type="Submit" name="OK" label="OK"> <!--- Use hidden fields to pass the first name, last name, and the three parts of the SSN# to the tax form. Also, create a hidden field for the filerID variable. ---> <cfinput type="hidden" name="FirstName" value="#getEmpInfo.FirstName#"> <cfinput type="hidden" name="LastName" value="#getEmpInfo.LastName#"> <cfinput type="hidden" name="Phone" value="#getEmpInfo.Phone#"> <cfinput type="hidden" name="SS1" value="#form.SS1#"> <cfinput type="hidden" name="SS2" value="#form.SS2#"> <cfinput type="hidden" name="SS3" value="#form.SS3#"> <cfinput type="hidden" name="taxFiler" value="#filerID#"> </cfform> The third ColdFusion page uses the cfpdfform and cfpdfformparam tags to populate the tax form with the user information. ColdFusion displays the tax prefilled tax form in the browser window where the user can complete the rest of the form fields. When the user clicks the submit button, Acrobat sends the completed PDF form to the ColdFusion processing page. Note: To prefill forms, map each PDF form field name
to the corresponding data element in a cfpdfformparam tag.
To view the form fields, open the form in Acrobat Professional and
select Forms > Edit Forms in Acrobat. For more information about
prefilling forms, see Manipulating PDF Forms in ColdFusion.
<!--- The following code populates the tax form template chosen from the list with information from the database query and the login form. Because no destination is specified, ColdFusion displays the interactive PDF form in the browser. A hidden field in the PDF form contains the name of the output file to write. It is a combination of the user name and the last three numerals of the user SSN#. The submit button added to the form created in Acrobat contains a URL to the ColdFusion processing page. ---> <cfpdfform source="taxForms/#form.myTaxForm#" action="populate"> <cfif "taxForms/#form.myTaxForm#" is "taxForms/f1040.pdf"> <cfpdfformparam name="f1_04(0)" value="#form.Firstname#"> <cfpdfformparam name="f1_05(0)" value="#form.Lastname#"> <cfpdfformparam name="f2_115(0)" value="#form.Phone#"> <cfpdfformparam name="f1_06(0)" value="#form.SS1#"> <cfpdfformparam name="f1_07(0)" value="#form.SS2#"> <cfpdfformparam name="f1_08(0)" value="#form.SS3#"> <cfpdfformparam name="filerID" value="#form.taxFiler#_1040"> <cfelseif "taxForms/#form.myTaxForm#" is "taxForms/f1040ez.pdf"> <cfpdfformparam name="f1_001(0)" value="#form.Firstname#"> <cfpdfformparam name="f1_002(0)" value="#form.Lastname#"> <cfpdfformparam name="f1_070(0)" value="#form.Phone#"> <cfpdfformparam name="f1_003(0)" value="#form.SS1#"> <cfpdfformparam name="f1_004(0)" value="#form.SS2#"> <cfpdfformparam name="f1_005(0)" value="#form.SS3#"> <cfpdfformparam name="filerID" value="#form.taxFiler#_1040ez"> </cfif> </cfpdfform> The fourth ColdFusion page uses the cfpdfform tag to process the PDF post submission and generate an output file. The filename is generated from the value of the hidden field in the tax form. The processddx action of the cfpdf tag uses the DDX instructions in the watermark.ddx file to generate a text-string watermark and apply it to the form. The following code shows the contents of the watermark.ddx file: <?xml version="1.0" encoding="UTF-8"?> <DDX xmlns="http://ns.adobe.com/DDX/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd"> <PDF result="Out1"> <PDF source="Doc1"> <Watermark rotation="30" opacity="65%"> <StyledText><p font-size="85pt" font-weight="bold" color="gray" font="Arial">FINAL</p></StyledText> </Watermark> </PDF> </PDF> </DDX> <!--- The following code reads the PDF file submitted in binary format and generates a result structure called fields. The cfpdfform populate action and the cfoutput tags reference the fields in the structure. ---> <cfpdfform source="#PDF.content#" action="read" result="fields"/> <cfpdfform action="populate" source="#PDF.content#" destination="FiledForms\#fields.filerID#.pdf" overwrite="yes"/> <!--- The following code verifies that the DDX file exists and the DDX instructions are valid. ---> <cfif IsDDX("watermark.ddx")> <!--- The following code uses the processddx action of the cfpdf tag to create a text- string watermark. ---> <!--- This code creates a structure for the input files. ---> <cfset inputStruct=StructNew()> <cfset inputStruct.Doc1="FiledForms\#fields.filerID#.pdf"> <!--- This code creates a structure for the output file. ---> <cfset outputStruct=StructNew()> <cfset outputStruct.Out1="FiledForms\#fields.filerID#.pdf"> <!--- This code processes the DDX instructions and applies the watermark to the form. ---> <cfpdf action="processddx" ddxfile="watermark.ddx" inputfiles="#inputStruct#" outputfiles="#outputStruct#" name="Final"> </cfif> <h3>Tax Form Completed</h3> <p>Thank you for filing your tax form on line. Copy this URL to view or download your filed tax form:</p> <cfoutput> <a href="http://localhost:8500/Lion/FiledForms/#fields.filerID#.pdf"> Link to your completed tax form</a> </cfoutput> |