| Package | flash.printing |
| Class | public class PrintJobOptions |
| Inheritance | PrintJobOptions Object |
options parameter of the PrintJob.addPage() method.
For more information about addPage(), see the PrintJob class.
See also
| Property | Defined By | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| printAsBitmap : Boolean = false
Specifies whether the content in the print job is printed as a bitmap or as a vector.
| PrintJobOptions | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| Method | Defined By | ||
|---|---|---|---|
|
PrintJobOptions(printAsBitmap:Boolean = false)
Creates a new PrintJobOptions object.
| PrintJobOptions | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
| printAsBitmap | property |
public var printAsBitmap:Boolean = false
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, you should 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);
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.completeHandler() method is called.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.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 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 | () | Constructor |
public function PrintJobOptions(printAsBitmap:Boolean = false)
Creates a new PrintJobOptions object. You pass this object
to the options parameter of the PrintJob.addPage() method.
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 |
See also