The 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.
- You specify the cfdocument attributes as Document object properties. You specify document content that is not in a section as a content element of the document object.
- You represent document sections in the documentSection element of the document object. The documentSection element is an arrays of objects, each of which represents a single document section. These objects include a content element for the section content, an optional documentItem element for the document items, and elements for any other section attributes.
- You represent all document items in a document section (or the document object) as an array of objects with type and content elements. The array element type field specifies whether the item is a header, footer, or page break. You specify the document item array as a documentItem element of the document object or a documentSection object.
- You call the document object execute() function to run the service.
The following excerpt from the full example shows how to create sections and items and add them to a document:
[Bindable] |
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> |