Skip to main content
April 21, 2009
Question

PrintJob Timeout

  • April 21, 2009
  • 1 reply
  • 1545 views

I'm trying to load a bunch of external images, and then print them all in the same PrintJob. For testing i tried 40 images at around 599kb.I load all images using Loaders and check that all images are fully loaded (by Event.INIT) and put the images in separate Sprites.
When this is done i start a new PrintJob, loop throug all my images and add them to the PrintJob, and then PrintJob.send();

At least this is what i want to do. What happens is this:

I load the images and store them in Sprites (PrintJob expects Sprites for printing)....
I start my PrintJob and check that it actually starts....

I start adding pages to the PrintJob in a loop that goes through all the Sprites....

****   this is where the problems start    ****
Since adding the pages takes some time, normally a few seconds per image, and the PrintJob.send() method takes some time i ALLWAYS exceeed the script timeout limit of (default) 15 seconds. The script stops adding pages and sends the PrintJob(???), resulting in a few correct pages and a few empty pages printed. I've tried  EVERYTHING and my conclusion is that printing many, or very large images simply can't be done...

The ActionScript 3.0 documentation says:

Note: ActionScript 3.0 does not restrict a PrintJob object to a single  frame (as did previous versions of ActionScript). However, since the operating  system displays print status information to the user after the user has clicked  the OK button in the Print dialog box, you should call  PrintJob.addPage() and PrintJob.send() as soon as  possible to send pages to the spooler. A delay reaching the frame containing the  PrintJob.send() call will delay the printing process.

Which is ,excuse my language, BULLSHIT!  The PrintJob does NOT have scope over multiple frames and HAS to be used in a single frame and is therefore limited to a total of 15 seconds from PrintJob.start() to PrintJob.send(), and this includes the time PrintJob.send() takes to finish.

The only way to get past this is to increase the "Script time limit" to a looooong time, and even that doesn't seem to do much difference.

If anybody would like to prove me wrong, please do!  >  mikaelnilsson77@hotmail.com

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 21, 2009

i loaded and printed 40 jpgs (each over 2 mb) without problem.

April 21, 2009

Hi!

Did you actually print the images or did you "print to file"?

Would you share that code with me?

/Mikael

kglad
Community Expert
Community Expert
April 21, 2009

(i'm not crazy:  i printed to a pdf.):

var spA:Array = [];
var i:int = 0;

loadF();

function loadF(){
     var sp:Sprite = new Sprite();
     var ldr:Loader = new Loader();
     var urlR:URLRequest = new URLRequest("image"+(i%4+1)+".jpg");
     sp.addChild(ldr);
     spA.push(sp);
     ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,f);
     ldr.load(urlR);
}

function f(e:Event){
     i++;
     if(i<40){
          loadF();
     } else {
          printF();
     }
}

function printF(){
     var pj:PrintJob = new PrintJob();
     if(pj.start()){
          for(i=0;i<spA.length;i++){
pj.addPage(spA);
}
pj.send();
}