加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex打印系列教程一使用flex内置打印函数

发布时间:2020-12-15 01:13:04 所属栏目:百科 来源:网络整理
导读:转载地址:http://bbs.9ria.com/archiver/tid-69833.html Adobe flex 内置的打印函数是相当简单明了的。对于单页打印来说,是最好不过的了。下面说下如何使用它们。 你要用到的类: ?mx.printing.FlexPrintJob 操作步骤如下: 1. 创建一个FlexPrintJob实例?

转载地址:http://bbs.9ria.com/archiver/tid-69833.html

Adobe flex 内置的打印函数是相当简单明了的。对于单页打印来说,是最好不过的了。下面说下如何使用它们。

你要用到的类:
?mx.printing.FlexPrintJob
操作步骤如下:
1. 创建一个FlexPrintJob实例? ??
? ?var flexPrintJob: FlexPrintJob = new FlexPrintJob();
2. 启动FlexPrintJob
? ?flexPrintJob.start();
3. 把要打印的组件传给FlexPrintJob?
? ?printJob.addObject(targetComponent);
4. 打印? ?printJob.send();

例子代码:[code]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
? ? ? ? <mx:Script>
? ? ? ? ? ? ? ? <![CDATA[
? ? ? ? ? ? ? ? ? ? ? ? import mx.printing.FlexPrintJob;
? ? ? ? ? ? ? ? ? ? ? ? import mx.collections.ArrayCollection;

? ? ? ? ? ? ? ? ? ? ? ? [Bindable]
? ? ? ? ? ? ? ? ? ? ? ? public var dataSource:ArrayCollection=new ArrayCollection();

? ? ? ? ? ? ? ? ? ? ? ? private var totalRecords:Number=15;

? ? ? ? ? ? ? ? ? ? ? ? private function init():void
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for(var i:int=1; i <= totalRecords; i++)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var dataObject:Object=new Object();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dataObject.Name="Name #" + i;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dataObject.Phone="Phone #" + i;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dataObject.Address="Address #" + i;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dataSource.addItem(dataObject);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? private function doPrint():void
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var printJob:FlexPrintJob=new FlexPrintJob();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (printJob.start())
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printJob.addObject(myData);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printJob.send();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ]]>
? ? ? ? </mx:Script>
? ? ? ? <mx:Panel title="Flex Tutorial - Print" width="500" height="500" horizontalCenter="0" verticalCenter="0" horizontalAlign="center" verticalAlign="middle">
? ? ? ? ? ? ? ? <mx:DataGrid id="myData" dataProvider="{dataSource}" width="400" height="400"/>
? ? ? ? ? ? ? ? <mx:Button label="Print" click="doPrint()"/>
? ? ? ? </mx:Panel>
</mx:Application>
[/code]结论:
Adobe Flex provides FlexPrintJob是为了解决打印问题的,它简单易用,但是它最大的问题是对于那些有滚动条,页面没有显示全部数据的,它只会打印出滚动条,而不会打印出所有的数据,在这里我将原文的意思改了下,因为这是我实验的结果,众位可以将上面的private var totalRecords:Number = 15;
改为
private var totalRecords:Number = 150;
然后打印下看看情况。

为了解决这些有滚动条组件的打印问题,dobe公司的Flex框架提供了一个解决方法。在接下来的教程中,我们将使用PrintDataGrid打印多个页面。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读