Your application can invoke a report by displaying the CFR file in a browser or by displaying a CFM page whose cfreport tag invokes the report.
You can optionally use the cfreport tag to save the report to a file.
The cfreport tag supports advanced PDF encryption options. For more information, see cfreport in the CFML Reference.
For information on report preview, see Previewing reports.
Display a report by using the cfreport tag
- Create a report, with or without an internal query.
- Create a CFM page and add a cfreport tag that invokes the report. If the report does not use an internal query, you must also populate a query and pass it using the query attribute. If the report uses an internal query and you use the query attribute, the passed query overrides the internal query.
<cfquery name="northwindemployees" datasource="localnorthwind">
SELECT EmployeeID, LastName, FirstName, Title, City, Region, Country
FROM Employees
ORDER BY Country, City
</cfquery>
<CFREPORT format="PDF" template="EmpReport.cfr"
query="#northwindemployees#"/>
Note: ColdFusion does not render text that occurs before or after the cfreport tag.
- Open a browser and display the CFM page.
ColdFusion generates the report.
If you display a report in HTML format, ColdFusion generates temporary files for images in the report. You can specify how long the temporary files are saved on the server by using the
resourceTimespan attribute of the
cfreport tag. For more information, see the
CFML Reference.
Display a CFR file in a browser
- Create a report that uses an internal query and does not use input parameters.
- Open a browser and display the CFR file.
Save a report to a file
- Create a report, with or without an internal query.
- Create a CFM page and add a cfreport tag that invokes the report. Optionally pass a query attribute, as described in the previous procedure. Include a filename attribute that specifies the fully qualified name of the file to be created, as the following example shows:
<CFREPORT format="PDF" template="emppicture.cfr"
filename="#GetDirectoryFromPath(GetTemplatePath())#/emppicture.pdf"
overwrite="yes"/>
If you write the report output to an HTML file, ColdFusion creates a directory located relative to the HTML file, generates files for the images (including charts) in the report, and stores the image files in the directory. For more information, see
Exporting the report in HTML format.
Use the .pdf extension for PDF output format, the .swf extension for FlashPaper output format, .xml extension for an XML file, .rtf extension for an RTF file, .html extension for HTML files, and the .xls extension for Excel format.
- Open a browser and display the CFM page. ColdFusion generates the report, saves the file, and displays an empty page in the browser.
Disable browser display of the CFR file
- Open the Report Properties dialog box by selecting Report > Report Properties from the menu bar.
- Clear the Allow Direct .CFR Browser Invocation option, and click OK.