Multipage printing class for AS3

June 12, 2009 by: Christian

A 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.

Multipage print class AS3

Try it out in the SWF below:
Get Adobe Flash player

You can find the documentation and download of all source files here.

.

Comments

24 Responses to “Multipage printing class for AS3”
  1. mbudm says:

    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.

  2. Jesse Gomez says:

    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.

  3. Majstor says:

    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

  4. Christian says:

    Hi Majstor
    It is easy: in turbohomepage.ch a swf is loaded into a movieclip, which is then printed. :-)

    Cheers,
    Christian

  5. Majstor says:

    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.

  6. gern says:

    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).

  7. Peter Unsworth says:

    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

  8. JLeRogue says:

    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?

  9. Christian says:

    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

  10. Dan says:

    Wow, this saved me a lot of work, thanks! :)

  11. Christian says:

    You’re welcome! :-)

  12. Joshua Cane says:

    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

  13. Christian says:

    Hi Joshua

    I don’t know if it is compatible, I have not yet found the time to implement it in Flex.

  14. Joshua Cane says:

    Thank you for your prompt response!

  15. Daniel Rogers says:

    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

  16. Christian says:

    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

  17. Test says:

    Check out this link.

    Its working for printing multiple pages

    http://www.actionscript.org/forums/showthread.php3?t=43201&page=2

  18. tasos says:

    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

  19. Lloyd says:

    This is really good, nice work :-)

    And of course, thank you!

  20. tasos says:

    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!

  21. Vinoth says:

    Links for documentation, source files and real examples are not working. Please may I have the source files and the documentation and I’m desperately in need of them for my college project where I need to print multiple pages. Your help will be highly appreciated. Thank in advance

  22. Christian says:

    Hi

    Thanks for the hint. I moved the server some time ago and therefor the links were broken. But now it is working again!

Leave a Reply

*