You want to display a datagrid in a PDF document generated on the fly by LCDS, but the documentation only gives scarce information about this.
Create a PDF form with a table in Adobe LiveCycle Designer, in Flex loop through the data provider of your datagrid and create a XML node for each row, then send the XML data to the LCDS server for the document generation.
Launch
Adobe LiveCycle Designer and create a new PDF form.
Create a new main
Subform and set its
Content to
Flowed in the
Object > Subform tab. Check
Allow Page Breaks within Content.
Within this new Subform, create two other subforms:
- Create a new
Subform for the table header. Set its
Content to
Positioned in the
Object > Subform tab.
Uncheck Allow Page Breaks within Content. Then create Text components for each column of your table. Arrange them horizontally.
- Create a new
Subform for the table rows. Set its
Content to
Positioned in the
Object > Subform tab. Uncheck
Allow Page Breaks within Content. Then create TextFields or Numeric Fields for each column of your table.
Define data binding for each Text Field in the Object > Binding tab.
Launch
Flex.
Here is a sample PDF form model. This model was extracted from the PDF form template with Acrobat Professional selecting Forms > Manage Form Data > Export Data. This model has all the nodes and bindings necessary for the TextFields captions and values as well as the for the Images. But
we miss the data for the table which should be the same as the data for the datagrid in the Flex UI.
<mx:XML id="XMLModel">
<transaction>
...
<invoiceNumber>{this.invoiceNumber}</invoiceNumber>
...
</transaction>
</mx:XML>
Write the method to generate the PDF document. In this method, loop through the data provider of your datagrid and create a new XML node for each row. The nodes must correspond to the binding names of the TextFields in the PDF form. Append this XML node to the rest of the XML model. When the
loop is done, trigger the document generation per se. Very important. You should start from a fresh copy of the model each time. Otherwise, you will add nodes to the model by reference, and the model will keep growing each time you invoke the method.
private function onGenerateAndOpenPDF():void
{
// -----------------------------------
// Parameters for the PDF Value Object
// -----------------------------------
// Get a fresh copy of the XML model to start from
// Otherwise, you will keep adding nodes to the same XML if you call this method several times
var document:XML = this.XMLModel.copy();
// Select the PDF XFA form to generate the document from
var filename:String = "debit_report_template.pdf";
// Add one XML node per billing document
for each(var billingDocument:FlxBillingDocument in this.model.debitReports.drBillingDocuments)
{
var newItem:XML =
<billingDocument>
<invoiceNumber>{billingDocument.externalBillingDocNr}</invoiceNumber>
<invoiceDate>{this.dateFormatter.format(billingDocument.externalBillingDocDate)}</invoiceDate>
<grossAmount>{this.numberFormatter.format(billingDocument.grossAmount)}</grossAmount>
<vatAmount>{this.numberFormatter.format(billingDocument.vatAmount)}</vatAmount>
<netAmount>{this.numberFormatter.format(billingDocument.grossAmount - billingDocument.vatAmount)}</netAmount>
</billingDocument>
document.appendChild(newItem);
}
trace(document);
// Create the PDF Value Object
var pdfVO:PDFVO = new PDFVO(document, filename);
// Call the Cairngorm command
var eventObject:GenerateAndOpenPDFEvent = new GenerateAndOpenPDFEvent(pdfVO);
CairngormEventDispatcher.getInstance().dispatchEvent( eventObject );
}