Flex打印(一)
用Flex进行打印可能是我迟早要做的事情,因为我在ANNCSR报表中迟早要实现Flash打印。Web应用的打印一直给我带来了困难的挑战,用浏览器来实现应用程序的打印,常常费力不讨好。
Flex打印利用2个新类来解决:FlexPrintJob和PrintDataGrid。
FlexPrintJob类会管理打印工作,并起到打印程序接口的作用:使用start()函数调用Print对话框,通过addObject()函数,添加打印项。
看代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox id="printContent" backgroundColor="#FFFFFF">
<mx:Label text="This is your first print text"/>
</mx:VBox>
<mx:Button x="30" y="30" label="Print This" click="testPrint()"/>
<fx:Script>
<![CDATA[
import mx.printing.FlexPrintJob;
private function testPrint():void
{
var print:FlexPrintJob = new FlexPrintJob();
if(print.start()){
print.addObject(printContent);
print.send();
}
}
]]>
</fx:Script>
</s:Application>
点击Print This就会弹出打印窗体,可继续打印。

浙公网安备 33010602011771号