flash.printing
public class PrintJobOptions
继承PrintJobOptions Inheritance Object

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

PrintJobOptions 类所包含的属性与 PrintJob.addPage() 方法的 options 参数配合使用。 有关 addPage() 的详细信息,请参见 PrintJob 类。

另请参见

PrintJob
PrintJob.addPage()
Flash Player 任务和系统打印


公共 属性
 属性定义方
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  printAsBitmap : Boolean = false
指定打印作业中的内容是将作为位图打印还是将作为矢量打印。
PrintJobOptions
 Inheritedprototype : Object
[static] 对类或函数对象的原型对象的引用。
Object
公共 方法
 方法定义方
  
PrintJobOptions(printAsBitmap:Boolean = false)
创建一个新的 PrintJobOptions 对象。
PrintJobOptions
 Inherited
指示对象是否已经定义了指定的属性。
Object
 Inherited
指示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
指示指定的属性是否存在、是否可枚举。
Object
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
属性详细信息
printAsBitmap属性
public var printAsBitmap:Boolean = false

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

指定打印作业中的内容是将作为位图打印还是将作为矢量打印。 默认值是 false,代表矢量打印。

如果要打印的内容包括位图图像,则请将 printAsBitmap 设置为 true,以包括任何 Alpha 透明度和色彩效果。 如果内容不包括位图图像,则应以较高品质的矢量格式(默认选项)打印内容。

例如,若要将内容作为位图打印,请使用以下语法:

         var options:PrintJobOptions = new PrintJobOptions(); options.printAsBitmap = true; myPrintJob.addPage(mySprite, null, options);
         


示例

下面的示例先加载一幅图片并放在矩形帧中,然后将该图片作为位图进行打印。
  1. 构造函数使用 LoaderURLRequest 对象加载该图片 (image.jpg)。 它还会检查在加载过程中是否发生了错误。 此处,假定该文件位于与 SWF 文件相同的目录中。 需要编译 SWF 文件,并将“本地回放安全性”设置为“只访问本地文件”。
  2. 在加载图片后(event 为 complete),将调用 completeHandler() 方法。
  3. completeHandler() 方法创建一个 BitmapData 对象,并在其中加载该图片(位图)。 将在 Sprite 对象中绘制一个矩形 (frame),并使用 beginBitmapFill() 方法在矩形中填充该图片(BitmapData 对象)。 还使用了 Matrix 对象缩放图像以适应该矩形。 (请注意,这会使图像发生扭曲。 本示例中使用此对象是为了确保图像与矩形相适应。) 在填充图像后,将调用 printPage() 方法。
  4. printPage() 方法创建一个新的打印作业实例,启动打印过程(将为用户调用打印对话框)并填充打印作业属性。 addPage() 方法包含有关打印作业的详细信息。 此处,将包含图片(Sprite 对象)的帧设置为作为位图打印,而不是作为矢量图形打印。 optionsPrintJobOptions 类的实例,并将其属性 printAsBitmap 设置为 true,以便作为位图打印(默认设置为 false)。

注意:仅为本示例定义了非常有限的错误处理代码。

package {
    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.display.BitmapData;    
    import flash.printing.PrintJob;
    import flash.printing.PrintJobOptions;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.net.URLRequest;
    import flash.geom.Matrix;

    public class printAsBitmapExample extends Sprite {

        private var frame:Sprite = new Sprite();
        private var url:String = "image.jpg";
        private var loader:Loader = new Loader();

        public function printAsBitmapExample() {

           var request:URLRequest = new URLRequest(url);
  
           loader.load(request);
           loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
           loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }

        private function completeHandler(event:Event):void {
        
            var picture:Bitmap = Bitmap(loader.content);
            var bitmap:BitmapData = picture.bitmapData;

           var myBitmap:BitmapData = new BitmapData(loader.width, loader.height, false);

            var matrix:Matrix = new Matrix();

            matrix.scale((200 / bitmap.width), (200 / bitmap.height));
            
            frame.graphics.lineStyle(10);
            frame.graphics.beginBitmapFill(bitmap, matrix, true);
            frame.graphics.drawRect(0, 0, 200, 200);
            frame.graphics.endFill();

            addChild(frame);
             
            printPage();    
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("Unable to load the image: " + url);
        }

        private function printPage ():void {
            var myPrintJob:PrintJob = new PrintJob();
            var options:PrintJobOptions = new PrintJobOptions();
            options.printAsBitmap = true;
            
            myPrintJob.start();
  
            try {
                myPrintJob.addPage(frame, null, options);
            }
            catch(e:Error) {
                trace ("Had problem adding the page to print job: " + e);
            }
 
            try {
            myPrintJob.send();
            }
            catch (e:Error) {
                trace ("Had problem printing: " + e);    
            }
        }
    }
}

构造函数详细信息
PrintJobOptions()构造函数
public function PrintJobOptions(printAsBitmap:Boolean = false)

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

创建一个新的 PrintJobOptions 对象。 请将此对象传递给 PrintJob.addPage() 方法的 options 参数。

参数
printAsBitmap:Boolean (default = false) — 如果为 true,则此对象作为位图打印。 如果为 false,则此对象作为矢量图打印。

如果要打印的内容包括位图图像,则请将 printAsBitmap 属性设置为 true,以包括任何 Alpha 透明度和色彩效果。 如果内容不包含位图图像,则请省略此参数,以便以较高品质的矢量格式(默认选项)打印内容。

另请参见





 

评论添加到页面后给我发送电子邮件 | 评论报告

当前页: http://livedocs.adobe.com/flash/9.0_cn/ActionScriptLangRefV3/flash/printing/PrintJobOptions.html