<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="1500"
height="900">
<fx:Script>
<![CDATA[
import
mx.controls.Alert;
import
mx.printing.FlexPrintJob;
import
mx.printing.FlexPrintJobScaleType;
private var
saveBitmapData:BitmapData;
private var
sp:Sprite;
private var
pj:PrintJob;
private var
print:FlexPrintJob;
protected function
button1_clickHandler(event:MouseEvent):void
{
print=new
FlexPrintJob();
print.printAsBitmap=true;
if(print.start())
{
Alert.show("startBegin");
try{
print.addObject(printGroup,FlexPrintJobScaleType.SHOW_ALL);
Alert.show("addObject");
}catch(e:Error){
Alert.show("addObjectError");
}
try{
print.send();
Alert.show("send");
}catch(e:Error){
Alert.show("sendError");
}
}else{
Alert.show("取消或遇到错误");
}
}
]]>
</fx:Script>
<fx:Declarations>
<!--
将非可视元素(例如服务、值对象)放在此处
-->
</fx:Declarations>
<s:Group
id="printGroup">
<s:BitmapImage id="img" width="1253"
height="768" horizontalCenter="0"
source="image/1.png"
verticalCenter="0"/>
</s:Group>
<s:Button x="503"
y="400" click="button1_clickHandler(event)"
content="打印"/>
</s:WindowedApplication>
原文地址:http://www.cnblogs.com/dongyl/p/3781731.html