ColdFusion 9.0 Resources |
Using the Document classThe Document class is the proxy for the ColdFusion Document
service, which provides the functionality of the cfdocument tag
and its child cfdocumentsection and cfdocumentitem tags.
The following excerpt from the full example shows how to create sections and items and add them to a document: [Bindable] var docItem:Array = [{type:"header",content:"<font size='-3'> <i>Salary Report</i></font>"},{type:"footer", content:"<font size='-3'> Page #cfdocument.currentpagenumber#</font>"}]; [Bindable]var docSectionItem:Array = [{content:"<table width='95%' border='2' cellspacing='2' cellpadding='2' > <tr><th>Salary</th></tr><tr> <td><font size='-1'>John</font></td> <td align='right'><font size='-1'>Guess What</font></td></tr> <tr><td align='right'><font size='-1'>Total</font></td> <td align='right'><font size='-1'>Peanuts</font></td></tr>", documentitem:docItem},{content:"content2",documentitem:docItem}]; . . . cfDoc.documentSection = docSectionItem; The following example shows some typical document use: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:cf="coldfusion.service.mxml.*" creationComplete="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.ResultEvent; import coldfusion.service.PdfParam; [Bindable] var docItem:Array = [{type:"header",content:" <font size='-3'><i>Salary Report</i></font>"}, {type:"footer",content:"<font size='-3'> Page <cfoutput>#cfdocument.currentpagenumber# </cfoutput></font>"}]; [Bindable] var docSection:Array = [{content:"content1"},{content:"content2"}, {content:"content3"}]; [Bindable] var docSectionItem:Array = [{content:"content1",documentitem:docItem}, {content:"content2",documentitem:docItem}, {content:"content3",documentitem:docItem}]; [Bindable] var res:String = new String(); private function init():void { doctestnow.execute(); } private function handleResult(event:ResultEvent):void { res=event.result.toString(); //Alert.show("httpurl= "+event.result.toString()); } private function handleError(event:Event):void { mx.controls.Alert.show(event.toString()); } ]]> </mx:Script> <cf:Config id="configid" cfServer="localhost" cfPort="80" servicePassword="service" serviceUserName="service" /> <!-- simple case--> <cf:Document id="doctestnow" action="generate" format="flashpaper" result="handleResult(event)" fault="handleError(event)" content="<table><tr><td>bird</td><td> 1</td></tr><tr><td>fruit</td>< td>2</td></tr><tr><td>rose</td> <td>3</td></tr></table>"/> <!--doc item case --> <!--<cf:Document id="doctestnow" action="generate" format="flashpaper" result="handleResult(event)" fault="handleError(event)" documentItem="{docItem}"/>--> <!-- doc section case--> <!--<cf:Document id="doctestnow" action="generate" format="flashpaper" result="handleResult(event)" fault="handleError(event)" documentSection="{docSection}"/>--> <!-- doc section and doc item case <cf:Document id="doctestnow" action="generate" format="flashpaper" result="handleResult(event)" fault="handleError(event)" documentSection="{docSectionItem}" />--> <mx:SWFLoader source="{res}"/> </mx:Application> |