Using flex build-in print function (the flex printing function series is reprinted)

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.