Extending Flex Components for PDF Generation in XDP Format

In this section, you’ll learn how to enhance standard Flex UI components so that they can properly present themselves for rendering as PDF-friendly objects in the XML-based XDP format.

The ActionScript code snippet in Example 11-13 shows how you can present a checkbox as an element of the PDF form in XDP format (in XDP, a checkbox is called checkButton).

We’ll introduce a new interface, IXdpObject, and each of our enhanced UI components will implement it to return properly prepared XML to represent itself. This will allow you to turn the entire Flex view into a searchable PDF.

Example 11-13 is an example of implementing the getter xdpContent() defined in the IXdpObject interface to produce a CheckBox in the XDP format.

Example 11-13. Representing a CheckBox as an XDP checkButton

// IXdpObject interface implementation
public  function get xdpContent():Object {
 var o:XML =
      <field  x={convert(x)} w={convert(width)} h={convert(height)}>
   <ui>
     <checkButton  allowNeutral="1">
       <border>
         <edge stroke="lowered"/>
         <fill/>
       </border>
      </checkButton>
   </ui>
   <value>
     <text>{value}</text>
   </value>
   <para vAlign="middle" hAlign="center"/>

   <items>
     <text>{onValue}</text>
     <text>{offValue}</text>
     <text></text>
   </items>
   <caption placement="bottom"/>
   </field>;

 return o;
}

private function convert(value:Number) : String {
   return  XdpUtil.px2pt(value) + "pt";
}

This code snippet includes a getter, xdpContent, that returns the representation of our CheckBox in ...

Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.