Monday, June 15, 2009

Flash/Flex: Printing to the Cloud

When David and I were doing the research for a paper we recently wrote, I came across the Adobe online documentation for Flex printing, which can be found here.

There are several classes discussed there: FlexPrintJob, which prints one or more objects and can split large objects for printing on multiple pages and scales the output to fit the page size. PrintDataGrid is subclass of the DataGrid control with a default appearance that is customized for printing. The class includes properties and a method that provide additional sizing and printing features. PrintAdvancedDataGrid is a subclass of the AdvancedDataGrid control with a default appearance that is customized for printing. The class includes properties and a method that provide additional sizing and printing features. FlexPrintJobScaleType defines constants used in the FlexPrintJob addObject() method.

These classes give the Flash/Flex developer control over how print can be generated from within the application. As one would expect from Adobe products, the output is designed to be directed to PostScript and "non-PostScript" printers.

While there is no native way direct the resulting print stream to the cloud, David and one of Mimeo's developers, a Flash/Flex guru Brad Johnson, came up with a way to accomplish this. An efficient and powerful (as well as simplified) way to print from the Flash/Flex platform would be to enable the developer to use the same mechanism and code path to print to the cloud as they can use to print locally today (e.g., like in the above example and described in Adobe documentation). In Flex 3 (at this writing, the latest iteration of the technology), the developer simply uses an instance of a PrintJob class, to start(), then uses addObject() one or more times, and finally employs send() print output to the OS for local printing.

To address printing in the cloud, a more universal (or web service) version of the PrintJob class would be created, perhaps called UniversalPrintJob that inherits it interface and capabilities from PrintJob but that adds the capabilities necessary for formatting and redirection of the output to the PSP. This class could provide an alternate implementation of PrintJob that would directly create a PDF or some other portable format from any Flex object added to the print job through the addObject method providing a great solution to the problem of creating an appropriate printable format.

Continuing this idea there could be additional properties, methods or parameters that could provide the additional information needed when the Send method is invoked to submit the content to a RESTful webservice. By simply providing a URL, additional job information and order data formatted as XML or JSON the send method could use the internal Flex HTTPService and/or WebService classes to seamlessly send this print job to a web enabled PSP.

3 comments:

  1. Interesting.

    How does Flex handle bitmaps for printing? In the past, there were issues with getting resolutions above 72/96dpi to the print stream. Is this still the case?


    Heath

    ReplyDelete
  2. Great question Heath! Flash 8/9 was 2,880 x 2,880

    With Flash 10, that's increased to 4,095 x 4,095

    ReplyDelete
  3. Hi Chuck,
    Thank you for this post. This is what I need now! As I am a new flex programmer, so still I am unclear about the implementation. Can you give me some detail information with exampls about I can use flex printing method and cloud print to print in a web printer from a android device?

    Thanks,

    Nahid

    ReplyDelete