Printing in Flex

I had to print something from Flex, but the LiveDocs weren't that helpful. I found this function and modified it to make it more generic...

<mx:Script>
   <![CDATA[
      import mx.core.IUIComponent;
      import mx.printing.FlexPrintJob;

      private function doPrint(printMe:IUIComponent):void{
         var pj:FlexPrintJob = new FlexPrintJob();
         if( pj.start() != true ){
            return;
         }
         pj.addObject(printMe);
         pj.send();
      }
   ]]>
</mx:Script>

Then define some display object you'll want to print. I loaded another component into this canvas.

<mx:Canvas
   id="formContent" backgroundColor="#ffffff"/>

And a button to print, passing it the component above. It's that simple!

<mx:Button label="Print" click="doPrint(formContent)"/>

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner