Understanding Flex Print Job from A to Z

What is FlexPrintJob

In Flex, you usually do printing in your application through FlextPrintJob.

According to Adobe, FlexPrintJob is:

  • A class that prints one or more objects
  • Automatically splits large objects for printing on multiple pages
  • Scales the output to fit the page size

FlexPrintJob vs. Flash PrintJob

FlexPrintJob is a new print class introduced by Adobe for Flex. In Flash, there is a similar one, named PrintJob.

Here is how you call FlexPrintJob in Flex:

flexPrintJob.addObject(myPrintObject,scaleType)
- myPrintObject is the UIComponent you want to print
- scaleType specifies how to scale UIComponent to fit print page
  (e.g. matchWidth, matchHeight, fillPage, showAll)

To compare, here is how you call PrintJob in Flash:

printJob.addPage(Sprite(myPrintObject), rectangle, printJobOptions)
- myPrintObject is the UIComponent you want to print
- rectangle is the print area defined by a rectangle
- printJboOptions specifies print as a BitMap or in Vector format

So, what is the relationship between those two print classes?

FlexPrintJob is actually a wrapper for PrintJob class.

What does a wrapper class mean in this case? It means:

1.  FlexPrintJob eventually calls Flash PrintJob to finish the printing task.

2.  FlexPrintJob enhances the Flash PrintJob and simplifies its usage.

What is new in FlexPrintJob

Adobe claims that FlexPrintJob automatically slices large object for printing on multiple pages and scales the output to fit the page size.

To do so,  FlexPrintJob wraps the old Flash PrintJob in the following 8 steps:

Step 1:  Convert percentage width or height to explicit width or height

Step 2:  Calculate Scale Ratio based on Print Page Size and ScaleType (e.g. matchWidth)

Step 3:  Scale the print object to the required value

Step 4:  Find the number of pages required in vertical and horizontal

Step 5:  Create the print area in a shape of rectangle

Step 6:  Specify Print Options (BitMap or Vector)

Step 7:  Call Flash PrintJob to print each page

Step 8:  Restore from explicit width or height to percentage width or height

What is missing in FlexPrintJob

FlexPrintJob enhances the Flash PrintJob in terms of scaling the output to fit the page size. However, is it good enough to print large object on multiple pages?

Maybe… as long as you don’t mind cutting text in half or printing only 5% content of TextArea or DataGrid.

As a matter of fact, to really support multiple pages printing in Flex, it need to resolve the following 3 issues:

1. How to scale display objects from screen to printer?

2. How to print the full content of Scrollable Components such as TextArea or DataGrid?

3. How to find the right page breaker to avoid cutting objects (e.g. Text or Image) in half?

Through the implementation of FlexPrintJob, it does not provide good answers to issue#2 and issue#3. Therefore, when come to printing multiple pages in Flex, you often need extra helps like PrintDataGrid or FlexReport.

About Bryan
Bryan Li has more than 10 years business consulting and project development experience with major corporate clients including Sony, Bank of Montreal, Bruce Power, etc. As a fan and advocate for RIA(Rich Internet Application) technologies, Bryan helps companies and developers learn, design, and build richer applications using Adobe Flex.

6 Comments on Understanding Flex Print Job from A to Z

  1. Tahir Alvi // October 29, 2009 at 2:25 am //

    I am very thanks full for this article.

    but i need to print images that i capture form a camera or video. then i store these images as a bitmap data. at the end i print four, two or six images in page.

    How i do that?

    Thanks

  2. Tahir Alvi // October 29, 2009 at 2:26 am //

    I am very thanks full for this article.

    but i need to print images that i capture form a camera or video. then i store these images as a bitmap data. at the end i print four, two or six images in page.
    Can u help me in this regard.?

    How i do that?

    Thanks

  3. I use FlexPrintJob to print an Image control but the color of the image turns more blue. It seems green or red color component has problem. Do you know why?

  4. We have a component that encapsulates all of the groundwork required, and provides a robust mechanism for print, print preview, pdf export, in addition to a lot of other really cool features! Please checkout http://www.flexicious.com and give us feedback!

  5. I noticed that FlexPrintJob use a lot of memory. In fact a datagrid of 200 record will required up to 800 MB of ram when sending data to the printer. Is there a way to save memory. My problem is that I have to print up to 1000 record and this will required 2 GB of RAM and the PC will crash.

  6. I noticed that flexPrinJob use a lot of memory while sending data to the printer. For Example 200 record (6 column each) use 600 MB of ram. I need to print up to 1000 record and the client crash because it needs over 2GB of ram. Is there a way to use less memory ?

Leave a comment

Your email address will not be published.

*