[AS3]as3打印功能的源代码
[AS3]as3打印功能的源代码
as3打印功能单页
- package{
- import flash.display.Sprite;
- import flash.printing.PrintJob;
- import flash.printing.PrintJobOptions;
- import flash.printing.PrintJobOrientation;
- import flash.geom.Rectangle;
- import flash.events.MouseEvent;
- public class BasicPrintExample extends Sprite{
- private var myPrintJob:PrintJob = new PrintJob();
- private var mySprite:Sprite = new Sprite();
- private var options:PrintJobOptions = new PrintJobOptions();
- private var rect1:Rectangle = new Rectangle(0,0,400,200);
- public function BasicPrintExample(){
- addChild(mySprite);
- mySprite.addChild(mc);
- btn.addEventListener(MouseEvent.CLICK, btnClick);
- }
- private function btnClick(e){
- printJob();
- }
- private function printJob(){
- options.printAsBitmap = true;
- myPrintJob.start();
- myPrintJob.addPage(mySprite,rect1,options);
- myPrintJob.send();
- }
- }
- }
as3打印功能多页打印
- package {
- //多页打印类
- import flash.display.MovieClip;
- import flash.printing.PrintJob;
- import flash.printing.PrintJobOrientation;
- import flash.display.Stage;
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.geom.Rectangle;
- import flash.events.MouseEvent;
- public class PrintMultiplePages extends MovieClip {
- private var sheet1:Sprite;
- private var sheet2:Sprite;
- private var sheet3:Sprite;
- public function PrintMultiplePages() {
- // constructor code
- init();
- btn.addEventListener(MouseEvent.CLICK, btnClick);
- }
- private function btnClick(e):void{
- printPages();//打印
- }
- private function init():void{
- sheet1 = new Sprite();
- createSheet(sheet1, "Once upon a time...",{x:10, y:50, width:80, height:130});
- sheet2 = new Sprite();
- createSheet(sheet2, "There was a great story to tell, and it ended quickly.\n\nThe end.", null);
- sheet3 = new Sprite();
- createSheet(sheet3, "你好,打印第三页!",null);
- }
- private function createSheet(sheet:Sprite, str:String, imgValue:Object):void{
- sheet.graphics.beginFill(0xeeeeee);
- sheet.graphics.lineStyle(1,0x000000);
- sheet.graphics.drawRect(0,0,100,200);
- sheet.graphics.endFill();
- var txt:TextField = new TextField();
- txt.height = 200;
- txt.width = 100;
- txt.wordWrap = true;
- txt.text = str;
- if(imgValue != null){
- var img:Sprite = new Sprite();
- img.graphics.beginFill(0x0066cc);
- img.graphics.drawRect(imgValue.x, imgValue.y, imgValue.width, imgValue.height);
- img.graphics.endFill();
- sheet.addChild(img);
- }
- sheet.addChild(txt);
- }
- private function printPages():void{
- var pj:PrintJob = new PrintJob();
- var pagesToPrint:uint = 0;
- if(pj.start()){
- if(pj.orientation == PrintJobOrientation.LANDSCAPE){
- throw new Error("Page is not set to an orientation of portrait.");
- }
- sheet1.height = pj.pageHeight;
- sheet1.width = pj.pageWidth;
- sheet2.height = pj.pageHeight;
- sheet2.width = pj.pageWidth;
- sheet3.height = pj.pageHeight;
- sheet3.width = pj.pageWidth;
- try{
- pj.addPage(sheet1);
- pagesToPrint++;
- }catch(e:Error){
- //响应错误
- }
- try{
- pj.addPage(sheet2);
- pagesToPrint++;
- }catch(e:Error){
- //响应错误
- }
- try{
- pj.addPage(sheet3);
- pagesToPrint++;
- }catch(e:Error){
- //响应错误
- }
- if(pagesToPrint>0){
- pj.send();
- }
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...