
1009
DEVELOPING
COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
Las
t
upda
te
d 8/5/2010
Creating basic reports from HTML and CFML
You can convert HTML-based reports into PDF or FlashPaper output by wrapping the HTML in the
cfdocument
start
and end tags, and specifying
cfdocument
attributes, as appropriate, to customize the following items:
•
Page size
•
Page orientation
•
Margins
•
Encryption (PDF only)
•
User password and owner password (PDF only)
•
Permissions (PDF only)
For complete information on these options, see the cfdocument tag discussion in the
CFML Reference
.
Note:
Embedding fonts in the report can help ensure consistent display across multiple browsers and platforms. For more
information on the considerations related to embedding fonts, see “
Creating a simple report
” on page
1036.
The following example displays a list of employees, using a cfoutput tag to loop through the query:
<cfdocument format="flashpaper">
<h1>Employee List</h1>
<!--- Inline query used for example purposes only. --->
<cfquery name="EmpList" datasource="cfdocexamples">
SELECT FirstName, LastName, Salary, Contract
FROM Employee
</cfquery>
<cfoutput query="EmpList">
#EmpList.FirstName#, #EmpList.LastName#, #LSCurrencyFormat(EmpList.Salary)#,
#EmpList.Contract#<br>
</cfoutput>
</cfdocument>
Creating sections, headers, and footers
You can use the cfdocument 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. Each document section starts on a new page.
The cfdocumentitem tag
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:
•
With
cfdocumentsection
: The
cfdocumentitem
attribute applies only to the section, and overrides previously
specified headers and footers.
•
Without
cfdocumentsection
: The
cfdocumentitem
attribute applies to the entire document, as follows:
•
If the tag is at the top of the document, it applies to the entire document.
•
If the tag is in the middle of the document, it applies to the rest of the document.
•
If the tag is at the end of the document, it has no affect.
You can use the
cfdocumentitem
tag to create a running header for an entire document, as the following example
shows: