Packageflash.printing
Classpublic class PrintJobOptions
InheritancePrintJobOptions Inheritance Object

Language version: ActionScript 3.0
Runtime version: 

The PrintJobOptions class contains properties to use with the options parameter of the PrintJob.addPage() method. For more information about addPage(), see the PrintJob class.

See also

PrintJob
PrintJob.addPage()


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  pixelsPerInch : Number = NaN
Specifies the resolution to use for bitmaps, in pixels per inch.
PrintJobOptions
  printAsBitmap : Boolean = false
Specifies whether the content in the print job is printed as a bitmap or as a vector.
PrintJobOptions
  printMethod : String
PrintJobOptions
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
  
PrintJobOptions(printAsBitmap:Boolean = false)
Creates a new PrintJobOptions object.
PrintJobOptions
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property detail
pixelsPerInchproperty
public var pixelsPerInch:Number = NaN

Language version: ActionScript 3.0
Runtime version: AIR 2

Specifies the resolution to use for bitmaps, in pixels per inch. The default value is Number.NaN, indicating that the native printer resolution is used.

The resolution setting is for both bitmap and vector printing. For bitmap printing, resolution controls how the entire page is rasterized. For vector printing, resolution controls how specific content, such as bitmaps and gradients, is rasterized.

printAsBitmapproperty 
public var printAsBitmap:Boolean = false

Language version: ActionScript 3.0
Runtime version: 

Specifies whether the content in the print job is printed as a bitmap or as a vector. The default value is false, for vector printing.

If the content that you're printing includes a bitmap image, set printAsBitmap to true to include any alpha transparency and color effects. If the content does not include bitmap images, print the content in higher quality vector format (the default option).

For example, to print your content as a bitmap, use the following syntax:

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

Note:Adobe AIR does not support vector printing on Mac OS.

See also


Example
The following example first loads a picture and puts it in a rectangle frame, then print the picture as a bitmap.
  1. The constructor loads the picture (image.jpg) using the Loader and URLRequest objects. It also checks if an error occurred during loading. Here the file is assumed to be in the same directory as the SWF file. The SWF file needs to be compiled with Local Playback Secuirty set to Access Local Files Only.
  2. When the picture is loaded (the event is complete), the completeHandler() method is called.
  3. The completeHandler() method, creates a BitmapData object, and loads the picture (bitmap) in it. A rectangle is drawn in the Sprite object (frame) and the beginBitmapFill() method is used to fill the rectangle with the picture (a BitmapData object). A Matrix object also is used to scale the image to fit the rectangle. (Note that this will distort the image. It is used in this example to make sure the image fits.) Once the image is filled, the printPage() method is called.
  4. The printPage() method creates a new instance of the print job and starts the printing process, which invokes the print dialog box for the user, and populates the properties of the print job. The addPage() method contains the details about the print job. Here, the frame with the picture (a Sprite object) is set to print as a bitmap and not as a vector. options is an instance of PrintJobOptions class and its property printAsBitmap is set to true in order to print as a bitmap (default setting is false).

Note: There is very limited error handling defined for this example.

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 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);    
            }
        }
    }
}

printMethodproperty 
printMethod:String  [read-write]Implementation
    public function get printMethod():String
    public function set printMethod(value:String):void
Constructor detail
PrintJobOptions()constructor
public function PrintJobOptions(printAsBitmap:Boolean = false)

Language version: ActionScript 3.0
Runtime version: 

Creates a new PrintJobOptions object. Pass this object to the options parameter of the PrintJob.addPage() method.

Parameters
printAsBitmap:Boolean (default = false) — If true, this object is printed as a bitmap. If false, this object is printed as a vector.

If the content that you're printing includes a bitmap image, set the printAsBitmap property to true to include any alpha transparency and color effects. If the content does not include bitmap images, omit this parameter to print the content in higher quality vector format (the default option).

Note:Adobe AIR does not support vector printing on Mac OS.

See also