您的位置:首页 > 其它

Flex 打印功能的相关资料

2014-09-29 17:33 357 查看
http://livedocs.adobe.com/flex/3_cn/flash/printing/PrintJob.html
http://hi.baidu.com/_678/blog/item/2b6fedc4d6104ba18226acb0.html/cmtid/ea780af32563c0c20b46e04e
Flex提供两种打印方法:FlexPrintJob和PrintJob。

一、由于flex是打印图像的缘故,打印出来的文字、表格会不清晰。解决方法如下:

1、将FlexPrintJob中printAsBitmap属性设置为true。

2、使用PrintJob

二、打印缩放的解决方法

1、FlexPrintJob.addObject()中 scaleType 可以使用 FlexPrintJobScaleType,FlexPrintJobScaleType中定义了缩放的几种常见方式。

<pre>

2、PrintJob默认为不缩放输出,如需要缩放可以使用 scale 属性

var pj:PrintJob = new PrintJob();

var xScale:Number;

var yScale:Number;

xScale = (pj.pageWidth / this.height);

yScale = (pj.pageHeight / this.width);

this.scaleX= Math.min(xScale, yScale);

this.scaleY = Math.min(xScale, yScale);

pj.addPage(this);

pj.send();

三、打印的横向和纵向的控制

1、判断打印方向

利用 PrintJob.orientation(图像打印方向) 判断,PrintJob.orientation == PrintJobOrientation.LANDSCAPE 或者 PrintJobOrientation.PORTRAIT(LANDSCAPE表示横向打印;PORTRAIT表示纵向打印)

2、如需改变方向

this.rotation = 90; 即表示旋转90度

3、转动后文字消失问题

绝大多数文字在转动后会出现消失问题,是由于字体的缘故。有两个解决方法:

(1)将字体加载到文件中,该方法缺点是对于中文而言消耗大,通常达到几M,英文常在几十K内。也可以用外嵌字体,将字体打包成另外一个swf文件,然后由主flash文件去外部调用

<pre>

@font-face

{

fontFamily: "simhei";

src: url("assets/simhei.ttf");

fontWeight: normal;

}

global

{

fontFamily: "simsun";

fontWeight: normal;

fontSize: 10;

color:#000000;

}

</pre>

<pre>

private function completeHandle(e:Event):void{

fontClass = Object(e.target.content).loaderInfo.applicationDomain.getDefinition("Font1") as Class

Font.registerFont(fontClass);

tt.styleName = "myPlainStyle"

tt.rotation = 30;

}

</pre>

(2)使用Bitmap和Bitmapdata类,将文字转化为图像后再转动。该方法消耗小,但是文字有可能失真,而且对每个文字组件都要进行转换。

var bmp:BitmapData = new BitmapData(aa.width,aa.height,true);

bmp.draw(aa);

var bt:Bitmap = new Bitmap(bmp);

var img:Image = new Image();

img.source = bt;

img.x = 200;

img.y = 200;

img.rotation = 120;

addChild(img);

转动后显示图像页会随之改变所以打印发送完毕后,要将显示的内容再旋转会去,参考http://jessewarden.com/2008/09/forcing-landscape-printing-in-flex-2-3.html

4、多页打印可使用PrintJob,请参见adobe使用示例
http://livedocs.adobe.com/flex/3_cn/flash/printing/PrintJob.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: