You can use the cfdocumentitem and cfdocumentsection tags to fine-tune your printable output, as follows:
cfdocumentitem
Creates page breaks, headers, or footers.
cfdocumentsection
Divides output into sections, optionally specifying custom margins. Within a section, use the cfdocumentitem
tag to specify unique headers and footers for each section.
You use one or more cfdocumentitem
tags to specify headers and footers or to create a page break. You can use cfdocumentitem
tags with or without the cfdocumentsection
tag, as follows:
cfdocumentsection
The cfdocumentitem
attribute applies only to the section, and overrides previously specified headers and footers.
cfdocumentsection
The cfdocumentitem
attribute applies to the entire document, as follows:
You can use the cfdocumentitem
tag to create a running header for an entire document, as the following example shows:
<cfdocument format="PDF"> <!--- Running header ---><cfdocumentitem type="header">
<font size="-3"><i>Directory Report</i></font>
</cfdocumentitem>
<h3>cfdirectory Example</h3> <!--- Use cfdirectory to display directories by name and size ---> <cfdirectory directory="#GetDirectoryFromPath(GetTemplatePath())#" name="myDirectory" recurse="yes" sort="directory ASC, name ASC, size DESC"> <!---- Output the contents of the cfdirectory as a cftable -----> <cftable query="myDirectory" htmltable colheaders> <cfcol header="DIRECTORY:" text="#directory#"> <cfcol header="NAME:" text="#Name#"> <cfcol header="SIZE:" text="#Size#"> </cftable> </cfdocument>
When using cfdocumentsection
, all text in the document must be enclosed within cfdocumentsection
tags. ColdFusion MX ignores HTML and CFML outside of cfdocumentsection
tags. The margin attributes override margins specified in previous sections or in the parent cfdocument
tag. If you specify margin attributes, the units are controlled by the unit attribute of the parent cfdocument
tag; the default for the unit attribute is inches.
Within a section, use the cfdocumentitem
tag to specify unique headers and footers for each section and a page break before each section, as the following example shows:
<cfquery datasource="cfdocexamples" name="empSalary"> SELECT Emp_ID, firstname, lastname, e.dept_id, salary, d.dept_name FROM employee e, departmt d WHERE e.dept_id = d.dept_id ORDER BY d.dept_name </cfquery> <cfdocument format="PDF"> <cfoutput query="empSalary" group="dept_id"><cfdocumentsection>
<cfdocumentitem type="header"> <font size="-3"><i>Salary Report</i></font> </cfdocumentitem> <cfdocumentitem type="footer"> <font size="-3">Page #cfdocument.currentpagenumber#</font> </cfdocumentitem> <h2>#dept_name#</h2> <table width="95%" border="2" cellspacing="2" cellpadding="2" > <tr> <th>Employee</th> <th>Salary</th> </tr> <cfset deptTotal = 0 > <!--- inner cfoutput ---> <cfoutput> <tr> <td><font size="-1"> #empSalary.lastname#, #empSalary.firstname#</font> </td> <td align="right"><font size="-1"> #DollarFormat(empSalary.salary)#</font> </td> </tr> <cfset deptTotal = deptTotal + empSalary.salary> </cfoutput> <tr> <td align="right"><font size="-1">Total</font></td> <td align="right"><font size="-1">#DollarFormat(deptTotal)#</font></td> </tr> <cfset deptTotal = 0> </table></cfdocumentsection>
</cfoutput> </cfdocument>