To populate a PDF file we need to have some requirements in
our system, such as Coldfusion or Adobe Acrobat full version.
These systems requirement some steps to be followed to
populate PDF files from ColdFusion.
Create a PDF document to populate
Create a document using either Microsoft Word or html. Adobe
Acrobat must be there to create a PDF for that document. Save it in WebServer
.
Insert required fields using Acrobat
Open the PDF in Acrobat and insert the fields using the menubar
Tools, like Form Tool, to create text fields. Then give a name to each field,
a font size and a style. The name of each field corresponds to the data given
as an input. Use the Text Tool to edit the text fields of fonts, size, etc. Save
it and place it in the WebServer.
Create a ColdFusion page to populate PDF
Now open any text editor and create a document; save it as
.cfm extension. Create a coldfusion form to collect data from the fields over
internet or using database query. This page will act as the way to populate
the PDF file.
Below we have the code for a FDF file.FDF (Form Data File) which
contains all the data to be merged with PDF.
Listing 1
(The CFM codes for Input)
<FORM ACTION="output.cfm" METHOD="POST" ENABLECAB="YES">
<P><B>First Name</B>
<INPUT TYPE="TEXT" NAME="fname"></P>
<P><B>Last Name</B>
<INPUT TYPE="TEXT" NAME="lname"></P>
<P><INPUT TYPE="SUBMIT" VALUE="Submit"></P>
</FORM>
(The Output Codes)
<CFSETTING ENABLECFOUTPUTONLY="YES" SHOWDEBUGOUTPUT="NO">
<CFCONTENT TYPE="APPLICATION/vnd.fdf">
<CFOUTPUT>
%FDF-1.2 --------- Header of FDF
1 0 obj <<
/FDF <<
/Fields -----------FDF body
[
<<
/T(date)
/V(#date#)
>>
<<
/T(fname)
/V(#form.fname#)
>>
<<
/T(lname)
/V(#form.lname#)
>>
]
/F(http://www.yoursite.com/pdf/file_name.pdf) ------- The path of the PDF file
>>
>>
endobj
trailer -------- FDF footer
<</Root 1 0 R>>
%%EOF
</CFOUTPUT>
Run the file and enter the required field to see the PDF
file given in /F tag.