Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : [FLMX04] PrintJob.orientation = "landscape";


Gallo_Teo
12/4/2005 3:06:58 PM

Hi to all, does any one know why PrintJob.orientation = "landscape";
doesn't work?
how have i to use it??

thanks
Teo


evollove
12/28/2005 11:42:20 PM
"landscape" is a read only property of the PrintJob object...
You can use it to detect if a user has selected landscape orientation in their
printer preferences.

See example below...
pClip is a reference to the movieClip you want to print

- hope this helps

function PrintMovieClip(pClip) {
//Create New Print Job
var PrintPages = new PrintJob();
//Start Page Printed Count
var pagesPrinted:Number = 0;
//If User Clicks 'Print' - start spooling pages & printing job
if (PrintPages.start()) {
//Get MovieClip original screen location
var origX:Number = this[pClip]._x;
var origY:Number = this[pClip]._y;
//Get Paper & Page size
pPageWidth = PrintPages.pageWidth;
pPageHeight = PrintPages.pageHeight;
pPaperWidth = PrintPages.paperWidth;
pPaperHeight = PrintPages.paperHeight;
//if the printer is set to landscape, rotate and position the MovieClip
if (PrintPages.orientation == "landscape") {
this[pClip]._rotation = 90;
this[pClip]._x = origX;
this[pClip]._y = origY;
}
//Get MovieClip size
clipWidth = this[pClip]._width;
clipHeight = this[pClip]._height;
//Get Reletive scale to paper size
clipXscale = (pPageWidth/clipWidth)*100;
clipYscale = (pPageHeight/clipHeight)*100;
//Scale MovieClip to fit on paper
this._xscale = clipXscale;
this._yscale = clipYscale;
//Get print area from MovieClip
PageMinX = this[pClip]._x;
PageMinY = this[pClip]._y;
PageMaxX = this[pClip]._width;
PageMaxY = this[pClip]._height;
//Add MovieClip as page to PrintJob
if (PrintPages.addPage(this[pClip], {xMin:PageMinX, xMax:PageMaxX,
yMin:PageMinY, yMax:PageMaxY}, null, 1)) {
pagesPrinted++;
}
}
trace("Total Pages to Print: "+pagesPrinted);
//If pages have been added to printJob, send them to the printer
if (pagesPrinted>0) {
PrintPages.send();
}
delete PrintPages;
}
ultimante
1/18/2006 9:28:43 AM
evollove, you should test code before posting it. you have a few major flaws
in your function.

when you rotate an image, its width and height are swapped. you didn't account
for that in your equation to determine scale.you're scaling the x and y
separately, which means the image will be stretched. you should take the
smaller scale of the two and apply it to both for a proportional scale.when you
rotate an image, its _x gets shifted. specifically for 90 degrees, its _x is
shifted by its _width, so you need to set its _x to _x + _width (not 0 or its
original x) to compensatePrintJob is a poorly written class in that it wants
you to scale the clip to fit it to the page, but then it wants you to pass it
the original width and height of the movieclip, not the adjusted width and
height of a rotated and/or scaled clip. the author of the PJ class should be
spanked.you set variables you never use, cluttering up your script.

here is the proper code, optimized for her pleasure:



function printImage(mc) {
var realW = mc._width;
var realH = mc._height;
pj = new PrintJob();
var pageCount = 0;
if (pj.start()) {
var cXscale, cYscale;
if (pj.orientation.toLowerCase() != "landscape") {
mc._rotation = 90;
mc._x = mc._width;
cXscale = (pj.pageWidth / realH) * 100;
cYscale = (pj.pageHeight / realW) * 100;
} else {
cXscale = (pj.pageWidth / realW) * 100;
cYscale = (pj.pageHeight / realH) * 100;
}
mc._xscale = mc._yscale = Math.min(cXscale, cYscale);
if (pj.addPage(mc, {xMin:0, xMax:realW, yMin:0, yMax:realH})) {
pageCount++;
}
}
if (pageCount > 0) {
pj.send();
}
mc._xscale = mc._yscale = 100;
mc._rotation = mc._x = mc._y = 0;
delete pj;
}
AddThis Social Bookmark Button