The build-in print function provided by Adobe Flex is actually pretty straightforward. For a single page print, it is good enough. Here is how it works:
Things you need
- MX. Printing. flexprintjob
Steps you do
1. Create a flexprintjob instance VaR flexprintjob: flexprintjob = new flexprintjob ();2. Start flexprintjobFlexprintjob. Start ();3. Add target component to flexprintjobPrintjob. addobject (targetcomponent );4. PrintPrintjob. Send ();
Sample Code
<? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX ="Http://www.adobe.com/2006/mxml"Layout ="Absolute"Initialize =" Init () "><Mx: SCRIPT><! [CDATA [import MX. Printing. flexprintjob; import MX. Collections. arraycollection; [Bindable] public var datasource: arraycollection = new arraycollection (); Private var totalrecords: Number =15; PrivateFunctionInit (): void {for (var I: Int = 1; I <= Totalrecords ; I ++) {var dataobject: Object = new object (); dataobject. Name =" Name # "+ I; dataobject. Phone =" Phone # "+ I; dataobject. Address =" Address # "+ I; datasource. additem (dataobject) ;}} private Function Doprint (): void {var printjob: flexprintjob = new flexprintjob (); If (printjob. start () {printjob. addobject (mydata); printjob. send () ;}}]> </MX: SCRIPT> <Mx: panel title =" Flex tutorial-print "Width =" 500 "Height =" 500 "Horizontalcenter =" 0 "Verticalcenter =" 0 "Horizontalalign ="Center "Verticalalign =" Middle "> <Mx: DataGrid id =" Mydata "Dataprovider =" { Datasource } "Width =" 400 "Height =" 400 "/> <Mx: button label =" Print "Click =" doprint () "/> </MX: Panel> </MX: Application>
Conclusion
Adobe Flex provides flexprintjob to handle the print request. It is very simple to use. However, the biggest challenge is printing multiple pages. In the above sample code, if you change the code,
From:
Private var totalrecords: Number =15;
To:
Private var totalrecords: Number =100;
It will generate100Records in the DataGrid. Guess how much of them will be printed if you click the print button? Depends on your page and printer setting, maybe just 17-20. You will even see a uugly vertical scoll bar. The problem here is, flexprintjob itself can notScollThose scollable components like DataGrid or textarea.
To resolve this problem, Adobe provides a workaround in flex framework. In the next tutorial, we will see printing multiple pages using printdatagrid.
Source: http://flextutorial.org/2009/05/21/using-flex-build-in-print-function/