FlexPrintJob 实现--------------------------------------------不涉及分页还算可以
(一)MyPrintView.mxml------------------打印辅助文件
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#FFFFFF"
height="250" width="450"
paddingTop="50" paddingLeft="50" paddingRight="50">
<!-- The controls to print, a PrintDataGrid control. -->
<!--这个控件来打印,PrintDataGrid控制。-->
<mx:PrintDataGrid id="myDataGrid" width="100%">
<mx:columns>
<mx:DataGridColumn dataField="Product"/>
<mx:DataGridColumn dataField="Code"/>
</mx:columns>
</mx:PrintDataGrid>
</mx:VBox>
(二)PrintJobExample.mxml----------------------------------------打印实现主文件
<?xml version="1.0" encoding="utf-8"?>
<!-- printing\DGPrintCustomComp.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
height="450"
width="550">
<mx:states>
<mx:State name="printView">
<mx:RemoveChild target="{myForm}"/>
<mx:AddChild position="lastChild">
<mx:Panel width="388" height="303" layout="absolute">
<mx:Image id="img" x="10" y="10"/>
</mx:Panel>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Button label="Back" click="currentState="""/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.printing.FlexPrintJob;
import com.MyPrintView;
import mx.graphics.ImageSnapshot;
import mx.core.UIComponent;
private function print(u:UIComponent):void{
currentState="printView";
var bmp:BitmapData = ImageSnapshot.captureBitmapData(u);
var i:Bitmap = new Bitmap(bmp);
img.source = i;
img.scaleContent = true;
}
//监听打印事件
public function doPrint():void {
// Create a FlexPrintJob instance.
//创建一个FlexPrintJob实例。
var printJob:FlexPrintJob = new FlexPrintJob();
// Start the print job.
if(printJob.start()) {
// Create a MyPrintView control as a child
//创建一个MyPrintView控制当作小孩看待当前视场。
// of the current view.
var formPrintView:MyPrintView = new MyPrintView();
addChild(formPrintView);
// Set the print control's data grid data provider to be
//设定打印控制的数据网格数据提供者
// the displayed data grid's data provider.
//显示的数据网格的数据提供者。
formPrintView.myDataGrid.dataProvider =
myDataGrid.dataProvider;
// Add the SimplePrintview control to the print job.
// 增加SimplePrintview控制到印刷工作。
// For comparison, try setting the
// 为比较的尝试设置
// second parameter to "none".
// 对“无的”第二个参量。
printJob.addObject(formPrintView);
// Send the job to the printer.
// 寄发工作到打印机。
printJob.send();
// Remove the print-specific control to free memory.
// 取消打印具体控制释放记忆。
removeChild(formPrintView);
}
}
]]>
</mx:Script>
<!-- The form to display-->
<mx:Form id="myForm">
<mx:FormHeading label="Contact Information"/>
<mx:FormItem label="Name: ">
<mx:TextInput id="custName"
width="200"
text="Samuel Smith"
fontWeight="bold"/>
</mx:FormItem>
<mx:FormItem label="Phone: ">
<mx:TextInput id="custPhone"
width="200"
text="617-555-1212"
fontWeight="bold"/>
</mx:FormItem>
<mx:FormItem label="Email: ">
<mx:TextInput id="custEmail"
width="200"
text="sam@sam.com"
fontWeight="bold"/>
</mx:FormItem>
<mx:FormHeading label="Product Information"/>
<mx:DataGrid id="myDataGrid" width="300">
<mx:dataProvider>
<mx:Object Product="Flash" Code="1000"/>
<mx:Object Product="Flex" Code="2000"/>
<mx:Object Product="ColdFusion" Code="3000"/>
<mx:Object Product="JRun" Code="4000"/>
</mx:dataProvider>
</mx:DataGrid>
<mx:Button label="PrintView" click="print(myDataGrid)"/>
<mx:FormItem label="Label">
</mx:FormItem>
<mx:Button id="myButton"
label="打印"
click="doPrint();"/>
</mx:Form>
</mx:Application>
分享到:
相关推荐
Flex 打印 例子 Flex 打印 例子 Flex 打印 例子
flex 打印源代码
关于Flex自带的打印及打印功能,代码较全,较容易理解。不错的资源!
Flex打印预览,本人找N久才找到希望能给朋友们帮上忙
flex 打印预览
flex打印机制,使用flex内置打印容器类解决打印问题。
flex 打印控件 应该说是相当完美了。 但只能够用于grid打印和打印预览
flex 打印小实例源码,已经测试过的,希望能对大家有所帮助。
NULL 博文链接:https://shuaiqixiao4.iteye.com/blog/650162
flex4.5 打印预览 分页 样式自调 带有预览功能 已通过测试
FlexReport.zip,这个是Flex的打印程序
有两个ArcGis实现的打印功能,以及使用的包,及查看例子的地址等.是自己做时的总结
FLEX内存释放优化原则,内存泄露解决方法,内存泄露情况
flex 带打印预览功能的PrintJob 经过我几天的努力,终于实现了flex的打印预览。把它做成了一个库文件,SuperPrintJob.swc。大家可以自由下载使用。这个压缩包中包含库文件的代码和使用的工程。详细的使用方法参见我...
* 使用Flex SDK 3.5 * 内有报表样式定义说明 * 内有Demo工程参考,使用MyReport * 不提供MyReport源码,提供swc组件(类似dll) * 只需少量工作就能把MyReport整合,获得良好的打印体现 * 效果图参考...
flex做的打印预览,很不错,大家可以了解一下
jasperreports+alivepdf+Flex解决打印和导出PDF问题
这是一个在flex端打印的一个测试,很实用
如果要使用分页效果,则必须使用标签"PrintAdvancedDataGrid"(Flex3中的标签)才能够实现分页效果,感兴趣的朋友可以参考下