Who Moved My Cheese! I try to be Haw Police at work for Musharraf League
Dec 08

PrintJob has been giving me a couple of problems lately, one of them was proper placement of the objects on page. This post discusses the fix

NOTE: I have not been able to confirm the behavior described here, may be it was just something i was doing wrong. However i am posting it here so that if it’s really a problem, this fix might help

Say, there’s a Sprite/MovieClip of a standard page size (say A4), say it’s called ‘p’, naturally you would print it as:

var pj:PrintJob = new PrintJob();
if(pj.start())
{
pj.addPage(p); // p is the Sprite/MovieClip of full page size
pj.send();
}

Say you had an rectangle (the only object in the Sprite) right in the middle of the sprite, since the sprite’s size equals the page size, you’ll expect the rectangle to be printed in the middle of the page, right? Surprise! it gets printed in the top left corner.

What happened here is that actionscript aligned the first drawn pixel (the top left corner of the rectangle) to the top left corner of the page. To workaround, you may draw an invisible rectangle of the full page size to the Sprite so that everything gets printed neatly. here’s what you would do:

var pj:PrintJob = new PrintJob();
if(pj.start())
{
p.graphics.lineStyle(1, 0xFFFFFF, 0);
p.graphics.drawRect(0, 0, PageWidth, PageHeight);

pj.addPage(p); // p is the Sprite/MovieClip of full page size
pj.send();
}

written by ishaq


Leave a Reply