Printing Custom Flex components using PrintJob

Someone on flexcoders asked about printing a Custom component using PrintJob.
I wrote a quick and dirty example. The idea is to create instance of component in main application, print it and delete it when printing is done.

##PrinJobExample.mxml###
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<mx:Script>
[CDATA[
import Help;
var helpRef;
function testPrintJob():Void
{
helpRef= createChild(Help, "help");
//wait untill help is created & rendered completely...
        helpRef.addEventListener("creationComplete",mx.utils.Delegate.create(this, printHelp));
}
function printHelp()
{
var printJob:PrintJob= new PrintJob();
printJob.start();
printJob.addPage(helpRef);
printJob.send();
delete printJob;
destroyChild(helpRef);
}
]]
</mx:Script>
<mx:Button label="print" click="testPrintJob();"/>
</mx:Application>
##Help.mxml###
<mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Label id="_lbl" text="Hello I am Help...."/>
<mx:Button label="Button in Help..."/>
</mx:VBox>
  • RBKB

    How can createChild() be used in Flex 3?

  • Razak

    Hi,
    could you please give an example of printing plain text with flex . In java we will write to output stream and convert it to printstream that will achieve printing. How could I do it with the support of flex?

  • kannan

    Hi,
    Is it possible to get multipage printout from AdvancedDataGrid?

  • @kannan: I think so, have not tried though.
    -abdul

  • Blake

    Have you guys tried BentBit Report? It is great at generating reports in Flex and it even lets your users view the pages, select the paper size and orientation, and it supports custom components. The website is http://www.bentbit.com/?goto=main/product.asp