Printing Custom Flex components using PrintJob
06 Apr 2005Someone 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>