I'm trying to print an Image and/or Canvas with ActionScript - however scaling doesn't work. I'm trying to scale down the image/canvas to have it fit to page. During testing it seems that Flex doesn't care if I set the size of the Image/Canvas trough width/height properties or scaleX/scaleY properties, it just chooses to print the content in its original size. If I set the size of the Image/Canvas specifically down inside the mXml tags, the content is correctly scaled to that size when printing.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" height="2000" width="750">
<mx:Script>
<![CDATA[
private function print():void {
var pj:PrintJob = new PrintJob();
if (pj.start()) {
var scaleX:Number = pj.pageWidth / printMe.width;
var scaleY:Number = pj.pageHeight / printMe.height;
var newScale:Number;
if (scaleX < scaleY)
newScale = scaleX;
else
newScale = scaleY;
if (newScale < 1.0) {
printMe.scaleY = printMe.scaleX = newScale;
debug("Scaling down to " + newScale);
}
else
debug("No scaling");
pj.addPage(printMe);
pj.send();
printMe.scaleY = printMe.scaleX = 1.0;
}
}
private function debug(msg:String):void {
trace("testprint: " + msg);
}
]]>
</mx:Script>
<!--
<mx:Image id="printMe" scaleContent="true" autoLoad="true">
<mx:source>http://www.firstpeople.us/pictures/bear/1600x1200/Forest_Wild_Grizzly_Bear-1600x1200.jpg</mx:source>
</mx:Image>
-->
<mx:Canvas id="printMe" width="648" height="1000" color="#B4B4B4" backgroundColor="#6B6B6B" borderStyle="none" borderColor="#FF0000" borderThickness="1">
<mx:Label y="0" text="Test test test" color="#FFFFFF" left="0"/>
<mx:Label text="Test test test" color="#FFFFFF" bottom="0" right="0" width="79" textAlign="right"/>
</mx:Canvas>
<mx:Button label="Print" click="print();"/>