This morning I decided I needed to tackle printing for the project I’m working on. I more or less expected to spend a good part of the day figuring it out. Boy was I wrong! I had my project printing output
While it’s entirely possible to get fancy (which I plan to do tomorrow) to start it’s as simple as
import the class for flex printing:
Create a new PrintJob, then start the print job.
printJob.start();
One thing to keep in mind. Once you’ve started the print job, don’t do too much (really don’t do any) non printing work. Don’t interact with the client, anything. Group all your printing.
then simply add items to the print job.
Each addObject is a new page in the printjob (so doing the above 10 times gets you 10 pieces of paper in the printer).
When you’re all done, send your printjob to the printer (really you’re sending it to the OS. From here the print dialogue will open in your OS
The object you pass the addObject() method can be a layout container (HBox, VBox, etc) or a single text object. My first run at printing, I wrapped my bits in a VBox, then passed the VBox to the addObject() method.
Once I got this solution soundly working I delved a bit deeper and found that a perhaps better solution is to create a printview component. Since often times (including my current project) your application looks a little different than what you’d like the printed output to look like. In my case I have some background colors and such that I don’t want on the print out. So my printview will simply be a component devoid of any colors.
All in all printing in Flex 2 is incredibly easy, in fact IMO much easier than printing in CF/HTML
.gif)

