Flex and PDF Generator Quick Start


Using WebORB PDF Generator from Flex is a simple and enjoyable task as document templates can be designed directly in Flex Builder. This guide will walk you through setting up a Flex Builder project, creating a simple PDF template and generating a document from it.

Prerequisites

Before you start, make sure to install the latest version of WebORB. Once WebORB server is installed, run the PDF Generator installer. The installer will install the PDF Generation engine into WebORB, add examples and user guide.

Set up a Flex Builder Project
  1. Create a Flex Builder project as described in the Flex Builder project setup with WebORB article.
  2. Add the PDF Generator client component library as described on this page.
Create PDF Template
  1. Right click project node and select New > MXML Component as shown in the image below. Use the default value (Canvas) as the base class for the template component. For consistency with the guide, name the template component MyTemplate:
  2. Open the new MXML component in the Design view and drag and drop the DataGrid and Label components and to your template. You can configure the width of the DataGrid component to be any size and the PDF Generator will render as such. In this guide, we will use constraint-based layout for the component:

    Layout constraints:

  3. Switch to the Source view of the MXML template component and modify the DataGrid MXML markup as shown below:
    <mx:DataGrid left=”10” right=”10” bottom=”10” height=”254
    dataProvider=”{‘method:Weborb.Examples.DataBinding.getCustomers()’}>
    <mx:columns>
    <mx:DataGridColumn
    dataField=”CONTACTNAME/>
    <mx:DataGridColumn
    dataField=”COMPANYNAME/>
    </mx:columns>
    </mx:DataGrid>
Add Code to Create a PDF
  1. Save the component and switch to the main application MXML file for the project. Open the Source view and add the following code:
    <mx:Script>
    <![CDATA[
    import com.tmc.weborb.pdf.PDFGenerator;

    public function createPDF():void
    {
    var template:MyTemplate = new MyTemplate();
    var pdfgen:PDFGenerator = new PDFGenerator( this );
    pdfgen.generatePDF( template );
    }
    ]]>
    </mx:Script>

  2. Modify the <mx:Application> tag to invoke the createPDF() function in the creationComplete event:
    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” xmlns:local=”*
    creationComplete=”createPDF()” >
  3. Save the code and run the application. Once the Flex application runs, it creates an instance of the template and sends it to the PDF Generator service. The services creates a document based on the template and returns a URL of the generated document. Flex client automatically opens the URL in a popup window.

~ by mjcprasad2000 on May 8, 2009.

Leave a comment