views:

541

answers:

2

//I can get the right margins by defining a rectangle and giving it the following dimensions:

var rect1:Rectangle = new Rectangle(0, 0, 792,612);

//When the print button is pressed the following code executes using the dimensions defined by rect1:

prntCover_btn.addEventListener(MouseEvent.CLICK, printCover);

function printCover(evt:MouseEvent):void {
    front_mc.visible = false;
     var myPrintJob:PrintJob = new PrintJob();
     var options:PrintJobOptions = new PrintJobOptions();
     options.printAsBitmap = true;
     front_mc.scaleX = 1;
     front_mc.scaleY = 1;
     myPrintJob.start();
     myPrintJob.addPage(front_mc, rect1, options);
     myPrintJob.send();

    }

//U.S.paper is 792 = 11.5 inch wide paper. Would like to use A3 size so I did this after the line myPrintJob.start();

var margin_height:Number = (myPrintJob.paperHeight - myPrintJob.pageHeight)/2;
var margin_width:Number = (myPrintJob.paperWidth - myPrintJob.pageWidth)/2;

This is not working to place the mc correctly on the page. This is all the Adobe help provides. Also Googled and tried different variations but no success. Can anyone help?

Thanks in advance for any insight into this.

Annie

A: 

You could clarify the question a bit because it is a bit unclear what you're trying to achieve... if I understood correctly, you probably want to print something in the middle of a larger paper.

You can get the paper size the user chose only after calling PrintJob.start() so you'll have to define the printArea parameter after that. As the printArea defines a rectangle relative to the DisplayObject being printed, in order to center the DisplayObject you'll have to make sure that the DisplayObject is in the center of the rectangle;

var myPrintJob:PrintJob = new PrintJob();
var options:PrintJobOptions = new PrintJobOptions();
options.printAsBitmap = true;
front_mc.scaleX = 1;
front_mc.scaleY = 1;
myPrintJob.start();

var marginWidth:Number = (myPrintJob.pageWidth - front_mc.width) / 2;
var marginHeight:Number = (myPrintJob.pageHeight- front_mc.height) / 2;
var rect:Rectangle = new Rectangle(-marginWidth, -marginHeight, myPrintJob.pageWidth, myPrintJob.pageHeight);

myPrintJob.addPage(front_mc, rect1, options);
myPrintJob.send();
kkyy
Your answer is exactly what I was searching for. Thank you so much.Anne
Annette B
Well, the best thank you would be an accepted answer...:)
kkyy
I now notice the check mark for accepting answers and I've checked it. Thanks again!Annie
Annette B
A: 

While this seems like it should work perfect, I have the problem that my diplayObject doesn't sit in the centre of the rec. It appear off centre and the result is the print is cropped. Have you any idea why this might be? I've been trying to figure this out for ages. i was using an alternative approach like this:

var pj:PrintJob = new PrintJob();
pj.start();
var sizeDiff:Number = new Number();
sizeDiff= pj.pageWidth - gaps_mc.width;
gaps_mc.width=gaps_mc.width+sizeDiff;
gaps_mc.height=gaps_mc.height+sizeDiff;
pj.addPage();
pj.send();
gaps_mc.width=gaps_mc.width-sizeDiff;
gaps_mc.height=gaps_mc.height-sizeDiff;

which stretched my clip to fit the page. This worked fine when I tested it from Flash, but when I uploaded it, the mc was getting cropped on the right side, even tho the values when returned seemed right, ie. pageWidth = mc.width.

Any help would be greatly appreciated as I'm going mad here!

mark