HOME > SUPPORT > COLDFUSION MX

Cold Fusion MX

 

Overview 

ReportMill makes it easy to generate PDF and Flash reports from ColdFusion MX applications, using ColdFusion's powerful Java integration features. Most ColdFusion developers are familiar with the RecordSet object, retrieved using the cfquery tag:

<cfquery name="myRecordSet" datasource="myDataSource">
   SELECT * FROM CUSTOMER
</cfquery>

Here's how easy it is to use ReportMill's API to turn a RecordSet into a PDF report:

<cfscript>
    template = CreateObject("Java", "com.reportmill.base.RMDocument");
    template.init("c:\MyTemplates\Template.rpt");
    report = template.generateReport(myRecordSet);
    report.writePDF(ExpandPath("MyReport.pdf"));
</cfscript>

See the Basic API document on the Support page for a complete list of ReportMill's primary API.

Adding ReportMill.jar to ColdFusion's ClassPath

The first step to use ReportMill with ColdFusion is to add ReportMill.jar to ColdFusion's classpath. Here are the steps:

  • Run ColdFusion Administrator
  • Select "Server Settings -> Java and JVM"
  • Add the complete path to your copy of ReportMill.jar (eg, "C:\MyJars\ReportMill.jar")
  • Restart the ColdFusion Administrator Service (under the Windows Start button: Programs->Admin Tools->Services)

Designing a ReportMill Template

The key to designing a ReportMill template is to get an XML file describing the data you will provide to ReportMill. ReportMill provides API to get this from any RecordSet (or any object for that matter). You only need to run this once (unless you change the columns in the RecordSet or database):

<cfscript>
    xmlWriter = CreateObject("Java", "com.reportmill.base.RMXMLWriter");
    xmlWriter.init();
    xmlWriter.writeObject(myRecordSet, "C:\Temp\MyRecordSet.xml");
</cfscript>

Once you have an XML file drag it into an empty document in the ReportMill editor. This will bind the XML to the document and present the user with the "Keys Browser". Simply drag and drop keys onto the template to begin (drag the "objects" to-many key on the template to create a table for repetitions).

It's important to note that you only need to generate XML once (for the purpose of template design), then you can delete this code. The "generateReport(myResultSet)" method runs directly from a ColdFusion ResultSet, and is about an order of magnitude more efficient than generating a report from XML.

Returning the Report to the Client Browser

Once you have generated a PDF or Flash document using writePDF() or writeFlash(), you can easily reference it using standard HTML (perhaps right under the cfscript tag used to generate the document):

<cfoutput><br><a href="MyReport.pdf">Here's the PDF!</a></cfoutput>

or

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=6,0,29,0"
width="#report.width#" height="#report.height#"> <param name="report" value="MyReport.swf"> <param name=quality value=high> <embed src="MyReport.swf" quality=high
pluginspage="http://www.macromedia.com/shockwave/
download/index.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash"
width="#report.width#" height="#report.height#">
</embed> </object>

Returning Reports as a Dynamic Response

It's often interesting to return a dynamically generated page as an HTTP response, so that the file doesn't actually exist in the doc root. This is simply a matter of providing the bytes instead of writing the file and changing the RESPONSE type to "application/pdf".

<cffile action="write" file="tempfis.pdf" output="#report.pdfBytes()#">
<cfcontent type="application/pdf" file="tempfis.pdf" deleteFile="Yes">

Cold Fusion JVM Configuration

When running ReportMill with ColdFusion on JVM 1.4, it is necessary to set the JVM to run "headless". See this Macromedia technote on the subject.

Troubleshooting

Other than the technote above, we've found using ReportMill with ColdFusion is not very different than using it with Java. However, when basic problems with page generation do occur, a good place to look is the ColdFusion error log: C:\CFusionMX\runtime\logs\default-err.log.

Additional Info

We're pretty new to ColdFusion - be sure and let us know if you can help us improve this document ([email protected]).