Flash and the challenge of Document Printing

Posted on March 23, 2011


For Q3 of 2011, I have planned the realization of Paperino (“Duck” in iItalian), which is a set of libraries to RAD applications and websites in flash.

Flash and the challenge of printing

While Flash offers you an interface / API to print content directly from Flash, this APIU is quite troubled, not to say crippled. As if someone started on the project and halfway through it was dropped.

Main issues with Flash Printing has are:

  1. You can not set DPI – while not a problem when printing vector content, it is an issue when printing as bitmap
  2. Printing as vector content does not work properly – there are two main issues here :
    1. Transparancy is not maintained – leading into solid shapes and loss of information (of the stuff underneath)
    2. Margins are not respected – Content can result into being offset too much to the top, bottom, left or right. This can differ between Windows and Mac. So you have no grip on positioning
  3. Printing as bitmap can lead to out of memory issues – Depending on your printers default DPI, FDlash will render the bitmaps accordingly. When your document has multiple pages, this can lead to issues on memory and speed / application freeze

Reports: Using Java, PDF and HTML

I used Crystal Reports a lot in the past. It is part of MS Access and works quite nicely.

To gain similar results in the Paperino framework, I decided not to use Flash, but Java to generate the reports for printing.

As I do not like the very low-level way to produce PDF documents I decided a while ago to use HTML as the “man in the middle” – like with the render engine of Paperino. HTML is a standard, in clear text format, quite well defined and very well supported in the community.

The reports can be generated from Flash or from Java. I can apply all tricks available (like grouping, colors in tables and selection of fonts) and using the right tools, I can add page breaks and the likes.

A quick search on: “PDF from HTML” delivered the following options:

  1. iText and Flying Saucer well documented and free if not commercially used
  2. PD4ML – A commercial HTML to PDF converter priced from 100 euro

I will investigate those in the near future.

Connecting the dots – Sockets

When the Flash-front end creates the HTML, the communication to Java will happen via Sockets. Part of the Paperino framework / libraries is a message based Socket Server once created for Roomware projects.

The print-job can be started from Java.

My current interest does not go further than offline use.

When used online, the web based app would very likely simply generate the PDF and offer it for download.

Rendering HTML in Flash?

One other thing om my list of “Things to do” is implementing XHTML. I have done part of that, using XHTML with the most basic parts (labels, buttons, divs) but they do not include tables.

  1. FlashML – Is a library apparently mainly focused on tables.
  2. HTMLwrapper – Is a library doing most if not all HTML (when it is clean)

HTML Tables – although cursed on by HTML developers – and yes: they suck for page layout – are a perfect tool to present… tables!

I might just do it myself, as mostr of the work is already done, including CSS parsing.

Posted in: Uncategorized