Using the Document class

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]
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="&lt;table&gt;&lt;tr&gt;&lt;td&gt;bird&lt;/td&gt;&lt;td&gt;
1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;fruit&lt;/td&gt;&lt;
td&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rose&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"/>
<!--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>

Adobe, Inc.

Get help faster and easier

New user?