flash.printingPrintUIOptions The PrintUIOptions class is used to specify options for print dialogs that are displayed to the user.Object The PrintUIOptions class is used to specify options for print dialogs that are displayed to the user. Create a PrintUIOptions instance, set its properties, and pass it as the uiOptions parameter of the PrintJob.showPageSetupDialog() or PrintJob.start2() method.

For example, the following code uses a PrintUIOptions instance to specify the min and max page numbers when the Page Setup dialog is displayed:

import flash.printing.PrintJob; var myPrintJob:PrintJob = new PrintJob(); if (myPrintJob.supportsPageSetupDialog) { var uiOpt:PrintUIOptions = new PrintUIOptions(); uiOpt.minPage = 1; uiOpt.maxPage = 3; myPrintJob.showPageSetupDialog(uiOpt); }
PrintJobPrintJob.showPageSetupDialog()PrintJob.start2()PrintUIOptions Creates a new PrintUIOptions object. Creates a new PrintUIOptions object. You pass this object to the uiOptions parameter of the PrintJob.showPageSetupDialog() or PrintJob.start2() method. PrintJob.showPageSetupDialog()PrintJob.start2()disablePageRange Specifies whether the page range in the print dialog is disabled (true) or the user can edit it (false).falseBooleanfalse Specifies whether the page range in the print dialog is disabled (true) or the user can edit it (false). The default value is false, indicating that there is no restriction on editing the page range. maxPage The maxiumum page number the user can enter in the print dialog.0uint0 The maxiumum page number the user can enter in the print dialog. The default value is 0, indicating that there is no restriction on the maximum page number. minPage The minimum page number a user can enter in the print dialog.0uint0 The minimum page number a user can enter in the print dialog. The default value is 0, indicating that there is no restriction on the minimum page number.
PrintMethod This class provides values for the PrintJobOptions.printMethod property to specify the method of printing a page.Object This class provides values for the PrintJobOptions.printMethod property to specify the method of printing a page. PrintJobOptions.printMethodAUTO Automatic selection of the best method of printing.autoString Automatic selection of the best method of printing. This value indicates that vector or bitmap printing is chosen automatically, based on the content to print. Vector printing is used whenever the content can be faithfully reproduced by that method. If transparency or certain other effects are present, bitmap printing is used instead.

This constant is used with the PrintJobOptions.printMethod property. Use the syntax PrintMethod.AUTO.

PrintJobOptions.printMethodVECTORBITMAP
BITMAP The bitmap method of printing.bitmapString The bitmap method of printing.

This constant is used with the PrintJobOptions.printMethod property. Use the syntax PrintMethod.BITMAP.

PrintJobOptions.printMethodVECTORAUTO
VECTOR The vector method of printing.vectorString The vector method of printing.

This constant is used with the PrintJobOptions.printMethod property. Use the syntax PrintMethod.VECTOR.

PrintJobOptions.printMethodBITMAPAUTO
PrintJobOptions The PrintJobOptions class contains properties to use with the options parameter of the PrintJob.addPage() method.Object 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. PrintJobPrintJob.addPage()PrintJobOptions Creates a new PrintJobOptions object.printAsBitmapBooleanfalseIf 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.

Creates a new PrintJobOptions object. Pass this object to the options parameter of the PrintJob.addPage() method.
PrintJob.addPage()
pixelsPerInch Specifies the resolution to use for bitmaps, in pixels per inch.NaNNumber 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.

printAsBitmap Specifies whether the content in the print job is printed as a bitmap or as a vector.falseBoolean 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.

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); } } } }
PrintJobOptions.printMethod
printMethod Specifies that the Flash runtime chooses the most appropriate printing method, or that the author wishes to explicitly select vector or bitmap printing.StringThe printMethod specified is not one of the values defined in the PrintMethod class. ArgumentErrorArgumentError Specifies that the Flash runtime chooses the most appropriate printing method, or that the author wishes to explicitly select vector or bitmap printing.

Set the property to one of the following values defined in the PrintMethod class:

  • PrintMethod.AUTO: Specifies that vector or bitmap printing is chosen automatically, based on the content to be printed. Vector printing will be used whenever the content can be faithfully reproduced by that method. If transparency or certain other effects are present, bitmap printing will be used instead.
  • PrintMethod.VECTOR: Speifies vector printing. This setting is the same as setting printAsBitmap to false.
  • PrintMethod.BITMAP: Specifies bitmap printing. Same as setting printAsBitmap to true.

If printMethod is set to one of these supported values, then printAsBitmap is ignored.

The default value is null; the printAsBitmap property is used.

PrintJobOptions.printAsBitmapPrintMethod class
PrintJob The PrintJob class lets you create content and print it to one or more pages.flash.events:EventDispatcher The PrintJob class lets you create content and print it to one or more pages. This class lets you render content that is visible, dynamic or offscreen to the user, prompt users with a single Print dialog box, and print an unscaled document with proportions that map to the proportions of the content. This capability is especially useful for rendering and printing dynamic content, such as database content and dynamic text.

Mobile Browser Support: This class is not supported in mobile browsers.

AIR profile support: This feature is supported on all desktop operating systems, but it is not supported on mobile devices or AIR for TV devices. You can test for support at run time using the PrintJob.isSupported property. See AIR Profile Support for more information regarding API support across multiple profiles.

Use the PrintJob() constructor to create a print job.

Additionally, with the PrintJob class's properties, you can read your user's printer settings, such as page height, width, and image orientation, and you can configure your document to dynamically format Flash content that is appropriate for the printer settings.

Note: ActionScript 3.0 does not restrict a PrintJob object to a single frame (as did previous versions of ActionScript). However, since the operating system displays print status information to the user after the user has clicked the OK button in the Print dialog box, you should call PrintJob.addPage() and PrintJob.send() as soon as possible to send pages to the spooler. A delay reaching the frame containing the PrintJob.send() call delays the printing process.

Additionally, a 15 second script timeout limit applies to the following intervals:

  • PrintJob.start() and the first PrintJob.addPage()
  • PrintJob.addPage() and the next PrintJob.addPage()
  • The last PrintJob.addPage() and PrintJob.send()

If any of the above intervals span more than 15 seconds, the next call to PrintJob.start() on the PrintJob instance returns false, and the next PrintJob.addPage() on the PrintJob instance causes the Flash Player or Adobe AIR to throw a runtime exception.

The following example show the basics of printing. A new PrintJob is created, and if started successfully, the addPage() method adds the sprite as a single page. The send() method spools the page to the printer. package { import flash.printing.PrintJob; import flash.display.Sprite; public class BasicPrintExample extends Sprite { var myPrintJob:PrintJob = new PrintJob(); var mySprite:Sprite = new Sprite(); mySprite.graphics.beginFill(0x336699); mySprite.graphics.drawCircle(100, 100, 50); public function BasicPrintExample() { if (myPrintJob.start()) { try { myPrintJob.addPage(mySprite); } catch(e:Error) { // handle error } myPrintJob.send(); } } } The following example uses the class PrintJobExample to create a small document and then send the document to the printer. This is accomplished using the following steps:
  1. Declare two variables of type Sprite named sheet1 and sheet2.
  2. Call init(), which assigns a new Sprite instance to both sheet1 and sheet2 and then calls createSheet() using different arguments.
  3. createSheet() does the following:
    1. The Sprite object passed in is used to draw a rectangle with a light-gray background, a one-pixel black border, and that is 100 pixels wide by 200 pixels high at x = 0, y = 0.
    2. A new TextField object is created named txt with the same dimensions as the Sprite, the wordWrap property set to true, and the text property set to the String passed as an argument to createSheet().
    3. If the Object argument passed is not null, create a new Sprite instance named img that is used to draw a white rectangle using the coordinate and dimension properties of the Object passed. The white rectangle is added to the display list of the Sprite object using addChild().
    4. The txt TextField is added to the display list of the Sprite object using addChild().
  4. Back in the constructor, the print method that is enabled (not commented out) is called. Since the methods are very similar, printOnePerPage() is described below.
  5. printOnePerPage() does the following:
    1. Declare a new PrintJob object named pj and pagesToPrint as a uint.
    2. Open the operating system's native print dialog box and wait for user to click OK.
    3. Check the orientation and if Landscape is selected, throw an error and exit.
    4. Set up the page height and width for sheet1 and sheet2.
    5. Send sheet1 and sheet2 to the print spooler using addPage().
    6. If the number of pages to print is > 0, print all spooled pages.
  6. The draw() method is called, which re-sizes the two Sprite properties to fit on the stage and re-positions sheet2 such that it is just right of sheet1.

Note: the constructor is set up such that one of three printing methods (one sheet per page, two sheets per page, or printing on the top half of the page) can be selected, based on preference. This example will not work correctly unless exactly two of the print methods are disabled using code comments. The example is set up such that printOnePerPage() will be called.

package { import flash.printing.PrintJob; import flash.printing.PrintJobOrientation; import flash.display.Stage; import flash.display.Sprite; import flash.text.TextField; import flash.geom.Rectangle; public class PrintJobExample extends Sprite { private var sheet1:Sprite; private var sheet2:Sprite; public function PrintJobExample() { init(); printOnePerPage(); // printTwoPerPage(); // printTopHalf(); draw(); } 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); } 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(0xFFFFFF); img.graphics.drawRect(imgValue.x, imgValue.y, imgValue.width, imgValue.height); img.graphics.endFill(); sheet.addChild(img); } sheet.addChild(txt); } private function printOnePerPage():void { var pj:PrintJob = new PrintJob(); var pagesToPrint:uint = 0; if(pj.start()) { if(pj.orientation == PrintJobOrientation.LANDSCAPE) { throw new Error("Without embedding fonts you must print one sheet per page with an orientation of portrait."); } sheet1.height = pj.pageHeight; sheet1.width = pj.pageWidth; sheet2.height = pj.pageHeight; sheet2.width = pj.pageWidth; try { pj.addPage(sheet1); pagesToPrint++; } catch(e:Error) { // do nothing } try { pj.addPage(sheet2); pagesToPrint++; } catch(e:Error) { // do nothing } if(pagesToPrint > 0) { pj.send(); } } } private function printTwoPerPage():void { var pj:PrintJob = new PrintJob(); var pagesToPrint:uint = 0; if(pj.start()) { if(pj.orientation == PrintJobOrientation.PORTRAIT) { throw new Error("Without embedding fonts you must print two sheets per page with an orientation of landscape."); } sheet1.height = pj.pageHeight; sheet1.width = pj.pageWidth/2; sheet2.height = pj.pageHeight; sheet2.width = pj.pageWidth/2; var sheets:Sprite = new Sprite(); sheets.addChild(sheet1); sheets.addChild(sheet2); sheets.getChildAt(1).x = sheets.getChildAt(0).width; try { pj.addPage(sheets); pagesToPrint++; } catch(e:Error) { // do nothing } if(pagesToPrint > 0) { pj.send(); } } } private function printTopHalf():void { var pj:PrintJob = new PrintJob(); var pagesToPrint:uint = 0; if(pj.start()) { if(pj.orientation == PrintJobOrientation.PORTRAIT) { throw new Error("Without embedding fonts you must print the top half with an orientation of landscape."); } sheet1.height = pj.pageHeight; sheet1.width = pj.pageWidth/2; sheet2.height = pj.pageHeight; sheet2.width = pj.pageWidth/2; var sheets:Sprite = new Sprite(); sheets.addChild(sheet1); sheets.addChild(sheet2); sheets.getChildAt(1).x = sheets.getChildAt(0).width; try { pj.addPage(sheets, new Rectangle(0, 0, sheets.width, sheets.height/2)); pagesToPrint++; } catch(e:Error) { // do nothing } if(pagesToPrint > 0) { pj.send(); } } } private function draw():void { var sheetWidth:Number = this.stage.stageWidth/2; var sheetHeight:Number = this.stage.stageHeight; addChild(sheet1); sheet1.width = sheetWidth; sheet1.height = sheetHeight; addChild(sheet2); sheet2.width = sheetWidth; sheet2.height = sheetHeight; sheet2.x = sheet1.width; } } }
The following example demonstrates additional printing features. The example initializes the PrintJob settings for number of copies, paper size (legal), and page orientation (landscape). It forces the Page Setup dialog to be displayed first, then starts the print job by displaying the Print dialog. package { import flash.display.Sprite; import flash.display.Stage; import flash.geom.Rectangle; import flash.printing.PaperSize; import flash.printing.PrintJob; import flash.printing.PrintJobOrientation; import flash.printing.PrintUIOptions; import flash.text.TextField; public class PrintJobExample extends Sprite { private var bg:Sprite; private var txt:TextField; private var pj:PrintJob; private var uiOpt:PrintUIOptions; public function PrintJobExample():void { var pj = new PrintJob(); uiOpt = new PrintUIOptions(); initPrintJob(); initContent(); draw(); printPage(); } private function printPage():void { if (pj.supportsPageSetupDialog) { pj.showPageSetupDialog(); } if (pj.start2(uiOpt, true)) { try { pj.addPage(this, new Rectangle(0, 0, 100, 100)); } catch (error:Error) { // Do nothing. } pj.send(); } else { txt.text = "Print job terminated"; pj.terminate(); } } private function initContent():void { bg = new Sprite(); bg.graphics.beginFill(0x00FF00); bg.graphics.drawRect(0, 0, 100, 200); bg.graphics.endFill(); txt = new TextField(); txt.border = true; txt.text = "Hello World"; } private function initPrintJob():void { pj.setPaperSize(PaperSize.LEGAL); pj.orientation = PrintJobOrientation.LANDSCAPE; pj.copies = 2; pj.jobName = "Flash test print"; } private function draw():void { addChild(bg); addChild(txt); txt.x = 50; txt.y = 50; } } }
PrintJob Creates a PrintJob object that you can use to print one or more pages. In Flash Player and AIR prior to AIR 2, throws an exception if another PrintJob object is still active. IllegalOperationErrorflash.errors:IllegalOperationError Creates a PrintJob object that you can use to print one or more pages. After you create a PrintJob object, you need to use (in the following sequence) the PrintJob.start(), PrintJob.addPage(), and then PrintJob.send() methods to send the print job to the printer.

For example, you can replace the [params] placeholder text for the myPrintJob.addPage() method calls with custom parameters as shown in the following code:

 // create PrintJob object
 var myPrintJob:PrintJob = new PrintJob();
  
 // display Print dialog box, but only initiate the print job
 // if start returns successfully.
 if (myPrintJob.start()) {
  
    // add specified page to print job
    // repeat once for each page to be printed
    try {
      myPrintJob.addPage([params]);
    }
    catch(e:Error) {
      // handle error 
    }
    try {
      myPrintJob.addPage([params]);
    }
    catch(e:Error) {
      // handle error 
    }
 
    // send pages from the spooler to the printer, but only if one or more
    // calls to addPage() was successful. You should always check for successful 
    // calls to start() and addPage() before calling send().
    myPrintJob.send();
 }
 

In AIR 2 or later, you can create and use multiple PrintJob instances. Properties set on the PrintJob instance are retained after printing completes. This allows you to re-use a PrintJob instance and maintain a user's selected printing preferences, while offering different printing preferences for other content in your application. For content in Flash Player and in AIR prior to version 2, you cannot create a second PrintJob object while the first one is still active. If you create a second PrintJob object (by calling new PrintJob()) while the first PrintJob object is still active, the second PrintJob object will not be created. So, you may check for the myPrintJob value before creating a second PrintJob.

PrintJob.addPage()PrintJob.send()PrintJob.start()
addPage Sends the specified Sprite object as a single page to the print spooler.Throws an exception if you haven't called start() or the user cancels the print job ErrorErrorspriteflash.display:SpriteThe Sprite containing the content to print. printAreaflash.geom:Rectanglenull A Rectangle object that specifies the area to print.

A rectangle's width and height are pixel values. A printer uses points as print units of measurement. Points are a fixed physical size (1/72 inch), but the size of a pixel, onscreen, depends on the resolution of the particular screen. So, the conversion rate between pixels and points depends on the printer settings and whether the sprite is scaled. An unscaled sprite that is 72 pixels wide prints out one inch wide, with one point equal to one pixel, independent of screen resolution.

You can use the following equivalencies to convert inches or centimeters to twips or points (a twip is 1/20 of a point):

  • 1 point = 1/72 inch = 20 twips
  • 1 inch = 72 points = 1440 twips
  • 1 cm = 567 twips

If you omit the printArea parameter, or if it is passed incorrectly, the full area of the sprite parameter is printed.

If you don't want to specify a value for printArea but want to specify a value for options or frameNum, pass null for printArea.

optionsflash.printing:PrintJobOptionsnullAn optional parameter that specifies whether to print as vector or bitmap. The default value is null, which represents a request for vector printing. To print sprite as a bitmap, set the printAsBitmap property of the PrintJobOptions object to true. Remember the following suggestions when determining whether to set printAsBitmap to true:
  • If the content 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, omit this parameter to print the content in higher quality vector format.

If options is omitted or is passed incorrectly, vector printing is used. If you don't want to specify a value for options but want to specify a value for frameNumber, pass null for options.

frameNumint0An optional number that lets you specify which frame of a MovieClip object to print. Passing a frameNum does not invoke ActionScript on that frame. If you omit this parameter and the sprite parameter is a MovieClip object, the current frame in sprite is printed.
Sends the specified Sprite object as a single page to the print spooler. Before using this method, you must create a PrintJob object and then use start() or start2(). Then, after calling addPage() one or more times for a print job, use send() to send the spooled pages to the printer. In other words, after you create a PrintJob object, use (in the following sequence) start() or start2(), addPage(), and then send() to send the print job to the printer. You can call addPage() multiple times after a single call to start() to print several pages in a print job.

If addPage() causes Flash Player to throw an exception (for example, if you haven't called start() or the user cancels the print job), any subsequent calls to addPage() fail. However, if previous calls to addPage() are successful, the concluding send() command sends the successfully spooled pages to the printer.

If the print job takes more than 15 seconds to complete an addPage() operation, Flash Player throws an exception on the next addPage() call.

If you pass a value for the printArea parameter, the x and y coordinates of the printArea Rectangle map to the upper-left corner (0, 0 coordinates) of the printable area on the page. The read-only properties pageHeight and pageWidth describe the printable area set by start(). Because the printout aligns with the upper-left corner of the printable area on the page, when the area defined in printArea is bigger than the printable area on the page, the printout is cropped to the right or bottom (or both) of the area defined by printArea. In Flash Professional, if you don't pass a value for printArea and the Stage is larger than the printable area, the same type of clipping occurs. In Flex or Flash Builder, if you don't pass a value for printArea and the screen is larger than the printable area, the same type of clipping takes place.

If you want to scale a Sprite object before you print it, set scale properties (see flash.display.DisplayObject.scaleX and flash.display.DisplayObject.scaleY) before calling this method, and set them back to their original values after printing. The scale of a Sprite object has no relation to printArea. That is, if you specify a print area that is 50 x 50 pixels, 2500 pixels are printed. If you scale the Sprite object, the same 2500 pixels are printed, but the Sprite object is printed at the scaled size.

The Flash Player printing feature supports PostScript and non-PostScript printers. Non-PostScript printers convert vectors to bitmaps.

PrintJob.send()PrintJob.start()DisplayObject class
selectPaperSize Set the paper size.if the paperSize parameter is not one of the acceptable values defined in the PaperSize class. ArgumentErrorArgumentErrorpaperSizeStringThe paper size to use for subsequent pages in the print job Set the paper size. The acceptable values for the paperSize parameter are constants in the PaperSize class. Calling this method affects print settings as if the user chooses a paper size in the Page Setup or Print dialogs.

You can call this method at any time. Call this method before starting a print job to set the default paper size in the Page Setup and Print dialogs. Call this method while a print job is in progress to set the paper size for a range of pages within the job.

import flash.printing.PrintJob; import flash.printing.PaperSize; var myPrintJob:PrintJob = new PrintJob(); myPrintJob.selectPaperSize(PaperSize.ENV_10);
PaperSizePrintJob.send()
send Sends spooled pages to the printer after successful calls to the start() or start2() and addPage() methods. Sends spooled pages to the printer after successful calls to the start() or start2() and addPage() methods.

This method does not succeed if the call to the start() or start2() method fails, or if a call to the addPage() method throws an exception. To avoid an error, check that the start() or start2() method returns true and catch any addPage() exceptions before calling this method. The following example demonstrates how to properly check for errors before calling this method:

var myPrintJob:PrintJob = new PrintJob(); if (myPrintJob.start()) { try { myPrintJob.addPage([params]); } catch(e:Error) { // handle error } myPrintJob.send(); }
PrintJob.addPage()PrintJob.start()PrintJob.start2()
showPageSetupDialog Displays the operating system's Page Setup dialog if the current environment supports it.if the system does not support Page Setup. Use the supportsPageSetupDialog property to determine if Page Setup is supported. IllegalOperationErrorflash.errors:IllegalOperationErrorif any print job (including the current one) is active. IllegalOperationErrorflash.errors:IllegalOperationErrortrue if the user chooses "OK" in the Page Setup dialog. This indicates that some PrintJob properties may have changed. Returns false if the user chooses "Cancel" in the Page Setup dialog. Boolean Displays the operating system's Page Setup dialog if the current environment supports it. Use the supportsPageSetupDialog property to determine if Page Setup is supported. import flash.printing.PrintJob; var myPrintJob:PrintJob = new PrintJob(); if (myPrintJob.supportsPageSetupDialog) { myPrintJob.showPageSetupDialog(); } PrintJob.supportsPageSetupDialogstart2 Optionally displays the operating system's Print dialog box, starts spooling, and possibly modifies the PrintJob read-only property values.If the Page Setup dialog is being displayed, or if another print job is currently active IllegalOperationErrorflash.errors:IllegalOperationErrorA value of true if the user clicks OK when the Print dialog box appears, or if the Print dialog is not shown and there is no error; false if the user clicks Cancel or if an error occurs. BooleanuiOptionsflash.printing:PrintUIOptionsnullAn object designating which options are displayed in the Print dialog that is shown to the user. If the showPrintDialog parameter is false, this value is ignored. showPrintDialogBooleantrueWhether or not the Print dialog is shown to the user before starting the print job Optionally displays the operating system's Print dialog box, starts spooling, and possibly modifies the PrintJob read-only property values.

The uiOptions parameter allows the caller to control which options are displayed in the Print dialog. See the PrintUIOptions class. This parameter is ignored if showPrintDialog is false.

Even when showPrintDialog is true, this method's behavior can differ from the start() method. On some operating systems, start() shows the Page Setup dialog followed by the Print dialog. In contrast, start2() never shows the Page Setup dialog.

In the following example, the min and max page settings in the Print dialog are set before the dialog is displayed to the user:

import flash.printing.PrintJob; import flash.printing.PrintUIOptions; var myPrintJob:PrintJob = new PrintJob(); var uiOpt:PrintUIOptions = new PrintUIOptions(); uiOpt.minPage = 1; uiOpt.maxPage = 3; var accepted:Boolean = myPrintJob.start2(uiOpt);
PrintJob.addPage()PrintJob.send()
start Displays the operating system's Print dialog box and starts spooling.in AIR 2 or later, if another PrintJob is currently active IllegalOperationErrorflash.errors:IllegalOperationErrorA value of true if the user clicks OK when the Print dialog box appears; false if the user clicks Cancel or if an error occurs. Boolean Displays the operating system's Print dialog box and starts spooling. The Print dialog box lets the user change print settings. When the PrintJob.start() method returns successfully (the user clicks OK in the Print dialog box), the following properties are populated, representing the user's chosen print settings: PropertyTypeUnitsNotesPrintJob.paperHeightNumberPointsOverall paper height.PrintJob.paperWidthNumberPointsOverall paper width.PrintJob.pageHeightNumberPointsHeight of actual printable area on the page; any user-set margins are ignored.PrintJob.pageWidthNumberPointsWidth of actual printable area on the page; any user-set margins are ignored.PrintJob.orientationString"portrait" (flash.printing.PrintJobOrientation.PORTRAIT) or "landscape" (flash.printing.PrintJobOrientation.LANDSCAPE).

Note: If the user cancels the Print dialog box, the properties are not populated.

After the user clicks OK in the Print dialog box, the player begins spooling a print job to the operating system. Because the operating system then begins displaying information to the user about the printing progress, you should call the PrintJob.addPage() and PrintJob.send() calls as soon as possible to send pages to the spooler. You can use the read-only height, width, and orientation properties this method populates to format the printout.

Test to see if this method returns true (when the user clicks OK in the operating system's Print dialog box) before any subsequent calls to PrintJob.addPage() and PrintJob.send():

var myPrintJob:PrintJob = new PrintJob(); if(myPrintJob.start()) { // addPage() and send() statements here }

For the given print job instance, if any of the following intervals last more than 15 seconds the next call to PrintJob.start() will return false:

  • PrintJob.start() and the first PrintJob.addPage()
  • One PrintJob.addPage() and the next PrintJob.addPage()
  • The last PrintJob.addPage() and PrintJob.send()
PrintJob.addPage()PrintJob.send()
terminate Signals that the print job should be terminated without sending. Signals that the print job should be terminated without sending. Use this method when a print job has already been initiated by a call to start() or start2(), but when it is not appropriate to send any pages to the printer. Typically, terminate() is only used to recover from errors.

After calling this method, the PrintJob instance can be reused. Wherever possible, the job's print settings are retained for subsequent use.

active Indicates whether a print job is currently active.Boolean Indicates whether a print job is currently active. A print job is active (the property value is true) in either of two conditions:
  • A Page Setup or Print dialog is being displayed.
  • The start() or start2() method has been called with a true return value, and the send() or terminate() method has not been called.

If this property is true and you call the showPageSetupDialog(), start(), or start2() method, the runtime throws an exception.

PrintJob.start()PrintJob.start2()PrintJob.send()PrintJob.terminate()
copies The number of copies that the print system prints of any pages subsequently added to the print job.int The number of copies that the print system prints of any pages subsequently added to the print job. This value is the number of copies entered by the user in the operating system's Print dialog. If the the number of copies was not displayed in the Print dialog, or the dialog was not presented to the user, the value is 1 (unless it has been changed by application code). firstPage The page number of the first page of the range entered by the user in the operating system's Print dialog.int The page number of the first page of the range entered by the user in the operating system's Print dialog. This property is zero if the user requests that all pages be printed, or if the page range was not displayed in the Print dialog, or if the Print dialog has not been presented to the user. isColor Indicates whether the currently selected printer at the current print settings prints using color (true) or grayscale (false).Boolean Indicates whether the currently selected printer at the current print settings prints using color (true) or grayscale (false).

If a color-or-grayscale value can't be determined, the value is true.

isSupported Indicates whether the PrintJob class is supported on the current platform (true) or not (false).Boolean Indicates whether the PrintJob class is supported on the current platform (true) or not (false). jobName The name or title of the print job.Stringif code attempts to set the property while the active property is true. IllegalOperationErrorflash.errors:IllegalOperationError<code>null</code> The name or title of the print job. The job name is typically used by the operating system as the title of the job in the print queue, or as the default name of a job that is printed to a file.

If you have not called start() or start2() and you haven't set a value for the property, this property's value is null.

For each print job you execute with a PrintJob instance, set this property before calling the start() or start2() method.

lastPage The page number of the last page of the range entered by the user in the operating system's Print dialog.int The page number of the last page of the range entered by the user in the operating system's Print dialog. This property is zero if the user requests that all pages be printed, or if the page range was not displayed in the Print dialog, or if the Print dialog has not been presented to the user. maxPixelsPerInch The physical resolution of the selected printer, in pixels per inch.Number The physical resolution of the selected printer, in pixels per inch. The value is calculated according to the current print settings as reported by the operating system.

If the resolution cannot be determined, the value is a standard default value. The default value is 600 ppi on Linux and 360 ppi on Mac OS. On Windows, the printer resolution is always available, so no default value is necessary.

orientation The image orientation for printing.String The image orientation for printing. The acceptable values are defined as constants in the PrintJobOrientation class.

Note: For AIR 2 or later, set this property before starting a print job to set the default orientation in the Page Setup and Print dialogs. Set the property while a print job is in progress (after calling start() or start2() to set the orientation for a range of pages within the job.

PrintJobOrientation class
pageHeight The height of the largest area which can be centered in the actual printable area on the page, in points.int The height of the largest area which can be centered in the actual printable area on the page, in points. Any user-set margins are ignored. This property is available only after a call to the PrintJob.start() method has been made.

Note: For AIR 2 or later, this property is deprecated. Use printableArea instead, which measures the printable area in fractional points and describes off-center printable areas accurately.

PrintJob.printableArea
pageWidth The width of the largest area which can be centered in the actual printable area on the page, in points.int The width of the largest area which can be centered in the actual printable area on the page, in points. Any user-set margins are ignored. This property is available only after a call to the PrintJob.start() method has been made.

Note: For AIR 2 or later, this property is deprecated. Use printableArea instead, which measures the printable area in fractional points and describes off-center printable areas accurately.

PrintJob.printableArea
paperArea The bounds of the printer media in points.flash.geom:Rectangle The bounds of the printer media in points. This value uses the same coordinate system that is used for subsequent addPage() calls. paperHeight The overall paper height, in points.int The overall paper height, in points. This property is available only after a call to the PrintJob.start() method has been made.

Note: For AIR 2 or later, this property is deprecated. Use paperArea instead, which measures the paper dimensions in fractional points.

PrintJob.paperArea
paperWidth The overall paper width, in points.int The overall paper width, in points. This property is available only after a call to the PrintJob.start() method has been made.

Note: For AIR 2 or later, this property is deprecated. Use paperArea instead, which measures the paper dimensions in fractional points.

PrintJob.paperArea
printableArea The bounds of the printer media's printable area in points.flash.geom:Rectangle The bounds of the printer media's printable area in points. This value uses the same coordinate system that is used for subsequent addPage() calls. printer Gets or sets the printer to use for the current print job.String Gets or sets the printer to use for the current print job. The String passed to the setter and returned by the getter should match one of the strings in the Array returned by the printers() method. To indicate that the default printer should be used, set the value to null. On operating systems where the default printer cannot be determined, this property's value is null. import flash.printing.PrintJob; var myPrintJob:PrintJob = new PrintJob(); myPrintJob.printer = "HP_LaserJet_1"; myPrintJob.start();

Setting the value of this property attempts to select the printer immediately. If the printer selection fails, this property's value resets to the previous value. You can determine if setting the printer value succeeds by reading the value after attempting to set it, and confirming that it matches the value that was set.

The printer property of an active print job cannot be changed. Attempting to change it after calling the start() or start2() method successfully and before calling send() or terminate() fails.

printers Provides a list of the available printers as String name values. Provides a list of the available printers as String name values. The list is not precalculated; it is generated when the function is called. If no printers are available or if the system does not support printing, the value is null. If the system supports printing but is not capable of returning a list of printers, the value is a Vector with a single element (its length property is 1). In that case, the single element is the actual printer name or a default name if the current printer name cannot be determined. supportsPageSetupDialog Indicates whether the Flash runtime environment supports a separate Page Setup dialog.Boolean Indicates whether the Flash runtime environment supports a separate Page Setup dialog. If this property is true, you can call the showPageSetupDialog() method to display the operating system's page setup dialog box. PrintJob.showPageSetupDialog()
PrintJobOrientation This class provides values that are used by the PrintJob.orientation property for the image position of a printed page.Object This class provides values that are used by the PrintJob.orientation property for the image position of a printed page. PrintJob.orientationLANDSCAPE The landscape (horizontal) image orientation for printing.landscapeString The landscape (horizontal) image orientation for printing. This constant is used with the PrintJob.orientation property. Use the syntax PrintJobOrientation.LANDSCAPE. PrintJob.orientationPORTRAITPORTRAIT The portrait (vertical) image orientation for printing.portraitString The portrait (vertical) image orientation for printing. This constant is used with the PrintJob.orientation property. Use the syntax PrintJobOrientation.PORTRAIT. PrintJob.orientationLANDSCAPEPaperSize This class provides the available values for the paperSize parameter of the PrintJob.selectPaperSize() method.Object This class provides the available values for the paperSize parameter of the PrintJob.selectPaperSize() method. Each constant represents a paper size that is used to print a page.

The following table shows the approximate size for each paper type. The size is approximate because there is some variation among printer drivers. For example, the width of A4 paper can be 595.0, 595.2, 595.22 or 595.28 points depending on the driver.

ValueSize in pointsA4595 x 842A5420 x 595A6297 x 420CHOUKEI3GOU340 x 666CHOUKEI4GOU298 x 666ENV_10297 x 684ENV_B5499 x 709ENV_C5459 x 649ENV_DL312 x 624ENV_MONARCH279 x 540ENV_PERSONAL261 x 468EXECUTIVE522 x 756FOLIO612 x 936JIS_B5516 x 729LEGAL612 x 1008LETTER612 x 792STATEMENT396 x 612
PrintJob.selectPaperSize()A4 A4 a4String A4 A5 A5 a5String A5 A6 A6 a6String A6 CHOUKEI3GOU Japanese choukei 3 gou (envelope) choukei3gouString Japanese choukei 3 gou (envelope) CHOUKEI4GOU Japanese choukei 4 gou (envelope) choukei4gouString Japanese choukei 4 gou (envelope) ENV_10 Legal envelope env_10String Legal envelope ENV_B5 B5 envelope env_b5String B5 envelope ENV_C5 C5 envelope env_c5String C5 envelope ENV_DL DL envelope env_dlString DL envelope ENV_MONARCH Monarch envelope env_monarchString Monarch envelope ENV_PERSONAL Personal envelope env_personalString Personal envelope EXECUTIVE Executive size executiveString Executive size FOLIO Folio size folioString Folio size JIS_B5 Japanese B5 jis_b5String Japanese B5 LEGAL Traditional legal size legalString Traditional legal size LETTER Traditional letter size letterString Traditional letter size STATEMENT Statement size statementString Statement size