-
PrintJob
Need a little help with the PrintJob function using Flash MX Pro.
I am trying to center the content of a MovieClip on the page when printing.
I have taken the pageWidth / 2 minus flashMC._width / 2 and set the flashMC._x equal to that amount... in theory that seems like it would work, however when printing the content is printed a little left of center.
Am I overlooking somthing? Any suggestions? Thanks.
-
Registered User
Moved from the Scripting and Backend forum.
-
Ryan Thomson
printing in flash sucks! sorry not very helpful
-
lol, quite alright, it does suck.
-
but... not anyone out there has figured out how to center print content with PrintJob... I have tried changing margins, adding fake content to force mcs to display farther right on the page when they print, chaning scale, but depending on printer setup and papersize, I need a way that will center content on the page, iv gotten close, but it just isn't center, no matter what I try. lol if you got any ideas I would appericiate it.
-
About a year too late!
Seeing as you posted this over a year ago I am guessing you might have figured out a solution or let the issue go. So this may be more for other people looking for the answer.
My document is 720px x 540px and i wanted to print it on letter paper which is 792px x 612px.
So this is the code that I used and it came out centered. I put it on the button itself.
Code:
on (keyPress "<Down>", release){
var my_pj:PrintJob = new PrintJob();
if (my_pj.start()) {
var pageAdded:Boolean = false;
//because my doc is landscape I have to roate it 90 degrees to print on a portrait page
_root._rotation = 90;
//Here i set the xMin to -36 because i wanted a 36 pixel margin (792-720=72/2=36) and I set my yMax to my doc size plus 36 (540+36=576)
pageAdded = my_pj.addPage(this,{xMin:-36,xMax:720,yMin:0,yMax:576});
if (pageAdded) {
my_pj.send();
}
}
//now you rotate back to the original setting
_root._rotation=0;
//clean up
delete my_pj;
}
-
Is there an equivalent for this in AS3? The bounds are determined by create a new Rectangle object. I can seem to get the Sprite scaled to fit a page, and centered, but the width & height seem to clip off half of the Sprite I need to print.
PHP Code:
var ts:BitmapData = takeSnapshot();
var _screengrab:Bitmap = new Bitmap(ts, "auto", true);
//good, now we need make sure it's printable...
var _screenshot:MovieClip = new MovieClip();
_screenshot.addChild(_screengrab);
_screenshot.x = -1*(_screenshot.width+1);
_screenshot.y = -1*(_screenshot.height+1);
addChild(_screenshot);
//New Print Job
var _pj:PrintJob = new PrintJob();
//Set Up Options
var _options:PrintJobOptions = new PrintJobOptions();
_options.printAsBitmap = true;
if (_pj.start())
{
var _scaleRatio:Number = 1.0;
var _scaleRatio2:Number = 1.0;
var _originalSW:Number = _screenshot.width;
var _originalSH:Number = _screenshot.height;
if(_pj.orientation.toLowerCase() == "landscape"){
_screenshot.rotation = 0;
//we need to size this bitmap data to make sure it all fits on the page.
if(_originalSW > _pj.pageWidth){
_scaleRatio = _pj.pageWidth/_originalSW;
_screenshot.scaleX = _scaleRatio;
_screenshot.scaleY = _scaleRatio;
}
if(_originalSH > _pj.pageHeight){
_scaleRatio2 = _pj.pageHeight/_originalSH;
if(_scaleRatio2 < _scaleRatio){
_screenshot.scaleX = _scaleRatio2;
_screenshot.scaleY = _scaleRatio2;
}
}
} else {
_screenshot.rotation = 90;
if(_originalSH > _pj.pageWidth){
_scaleRatio = _pj.pageWidth/_originalSH;
_screenshot.scaleX = _scaleRatio;
_screenshot.scaleY = _scaleRatio;
}
if(_originalSW > _pj.pageHeight){
_scaleRatio2 = _pj.pageHeight/_originalSW;
if(_scaleRatio2 < _scaleRatio){
_screenshot.scaleX = _scaleRatio2;
_screenshot.scaleY = _scaleRatio2;
}
}
}
try
{
trace("PRINT",_screenshot.x, _screenshot.y, _screenshot.width,_screenshot.height, _pj.orientation.toLowerCase(),_pj.pageWidth, _pj.pageHeight);
var sx:Number = - ((_pj.pageWidth-_screenshot.width)/2);
var sy:Number = - ((_pj.pageHeight-_screenshot.height)/2);
var bounds:Rectangle = new Rectangle(sx, sy, _pj.pageWidth, _pj.pageHeight);
trace("BOUNDS: ",bounds.x, bounds.y, bounds.width, bounds.height, bounds.topLeft, bounds.bottomRight);
_pj.addPage(_screenshot, bounds, _options);
}
catch (error:Error)
{
// Do nothing.
}
try
{
_pj.send();
}
catch (error:Error)
{
// do nothing...
}
}
else
{
//printjob cancelled by user
}
"Litter is my most treacherous foe. I would like to eat its children."
-Drederick Tatum
-
hello there, as anyone figured out why the print function produces completely blurred (pixelated) prints? (even if the objects printed are vectors) ? Is it only on macs? Thanks for your help!
-
Originally Posted by MDiddy
Is there an equivalent for this in AS3? The bounds are determined by create a new Rectangle object. I can seem to get the Sprite scaled to fit a page, and centered, but the width & height seem to clip off half of the Sprite I need to print.
I ported my AS2 print class to AS3 today, had the same issue, seems you have to make the rectangle large enough to account for your newly-created margins;
Code:
var bounds:Rectangle = new Rectangle(sx, sy, _pj.pageWidth +Maths.abs(sx), _pj.pageHeight +Maths.abs(sy));
ie., if your printable area is say 600 wide and your clip is 500 wide, sx will be -50 as a margin, but you also need to add 50 to the _pj.pageWidth to counter this.
Same with height, though I limit the max top margin on mine, doesn't look right when a Letter-sized printout is vertically centred on an A4 page; we hard-limit our prints to Letter-ish size, as even thought here in Aus A4 is the standard, most print drivers default to Letter, so we allow for the lowest common denominator. And some clients don't like content to be scaled down if it can be avoided (though I do have an inbuilt scaling system as a catch-all)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|