Multipage printing class for AS3
June 12, 2009 by: ChristianA little off topic, but it is something I have been in need of for a long time: multipage printing. I’ve been searching to find a class for AS3 that does this, but I have only found instructions and basic explanations on how to use the printjob class of AS3. So I used to tell my clients, uuh, printing is quite difficult in flash and they were always brave and I could skip it. But it has become more and more demanded and so I have created my own class. You can download it for free. Any feedback is highly appreciated!
How does it work?
It takes the content (movieclip or sprite), resizes it (keeping its aspect ratio) so that the width fits to the width of the selected paper format (landscape or portrait) and calculates the number of pages.

Try it out in the SWF below:
You can find the documentation and download of all source files here.
Here is a real example that makes use of the multipage printing class.
.






Nice, I’ll test this out in a couple of weeks when I will be needing a printmanager class for a new flash site template I’m going to make that just screams out the need for multipage printing.
Trouble is I’m sticking to as2 for the moment because that seems to sell a bit better on the stock site I use. I did a bit of research and there didn’t seem to be a big difference to printing from as2 to as3 (the 15 second timeout problem is still around right?).
So if I end up converting this back to as2 I’ll let you know and make it available as well.
Hello, I just wanted to say thanks for releasing this class. It’s functional and useful and I am currently using it in an educational interactive for the University of North Texas. with the obviously tiny, non-commercial budgets we have, the generosity of people like you really make a difference. Thanks again – Jesse.
Hello All,
and first many thanx to Christian for this great class!
Second, I have a question:
How to print whole swf??
(it is possible to do it in real example linked above: http://www.turbohomepage.ch/)
Greetz
Majstor
Hi Majstor
It is easy: in turbohomepage.ch a swf is loaded into a movieclip, which is then printed.
Cheers,
Christian
HI Christian
Thx for quick respond, also for your easy answer.
Also, I just solve my problem, and again it is easy:
var printJob:PrintJob = new PrintJob();
var pjo:PrintJobOptions = new PrintJobOptions();
pjo.printAsBitmap = true; //if you want to preserve any alpha transparency or color effects, print the page as a bitmap image!!
if (printJob.start())
{
printJob.addPage(this, null, pjo);
printJob.send();
}
So, if you like print (via button inside your swf) whole swf using command addPage, just put addPage(this);
I searched Internet, but never I found this solution, there are a lot of examples how to print single movieclip (http://www.riacodes.com/), or your example how to have single or multi page printout…
After many hours of searching, I just tried above solution and it is working.
By the way, in my case, I am possible to print my swf (page), no matter if the page is displayed in FF, IE, Opera or Chrome, even some of browsers still showing blank page when you chose PrintPreview from browser.
Printing in flash is always a nightmare. Director was better, but not by much. I can’t believe Adobe can’t implement some pagination or something from InDesign or even make it easier to create PDFs.
Testing this is interesting. It printed 3 pages to my laser printer, but only 1 to my PDF printer (only 1 page in the final PDF).
Hi,
I have been trying to print to multiple pages for days now and have tried hundreds of different ways. I was almost ready to give up when I found this class.
Thank you for posting this – it has worked perfectly, exactly what I was looking for.
Who would have ever thought printing in Flash would be such hard work.
Thanks again
Thanks, Peter!
Hi Christian, this class is terrific, and almost exactly what I need. I continue to experience one problem: Only the graphic children of my Sprite print. The textFields do not. I’m wondering what I’m doing wrong?
Are the fonts embedded? I’m not sure if this is the problem. Could you mail me your file so I can try to reproduce it?
Cheers,
Christian
Wow, this saved me a lot of work, thanks!
You’re welcome!
Hello, I am wondering if this is compatible with Flex 4 (Flash Builder 4)? I am getting a addChild() is not available in this class (Print.as). When I change it to addElement I get a undefined method error.
Thank you,
Josh
Hi Joshua
I don’t know if it is compatible, I have not yet found the time to implement it in Flex.
Thank you for your prompt response!
I am using your Actionscript class and it works great. Thanks a ton for posting this.
I tested the printing from different browsers/operating systems, and the text gets cut off in different places from one PC to another PC. Also looks different on a Mac, Have you run into this problem? Do you have any suggestions on how to make the print out consistent no matter where its printed?
Thanks,
Daniel
Hi Daniel
I have not run into this problem yet, but I would suggest to set the margins to be sure all content is printed, even if it means it is smaller. Have you tried this?
Cheers,
Christian
Check out this link.
Its working for printing multiple pages
http://www.actionscript.org/forums/showthread.php3?t=43201&page=2
Hi, thanx for this class, it has helped me a lot.
I have a problem though:
When i test the file locally, everything works fine, but when i upload to a server i get only blank pages.
Does anybody hava any ideas about this?
Thanx in advance
This is really good, nice work
And of course, thank you!
hello, sorry to came back with this issue but i have not managed to solve this problem yet, so if anyone has any suggestions it would be very helpfull
“When i test the file locally, everything works fine, but when i upload to a server i get only blank pages.”
I had corrected this problem by using setPrintAsBitmap(true) but it suddenly and without changing anything, it stopped working.
Thanx!