Packagecom.yworks.canvas
Classpublic class CanvasPrinter
InheritanceCanvasPrinter Inheritance flash.events.EventDispatcher

This class provides printing capabilities for a CanvasComponent.

Clients can use the various options provided by this class for customizing the printed output of a CanvasComponent.

MXML SyntaxexpandedHide MXML Syntax
	 <yworks:CanvasPrinter id="printer" canvas="{graphCanvas}" backgroundColor="0xFFFFFF" />
	 


Public Properties
 PropertyDefined By
  backgroundColor : *
The color that will be used to fill the background of the printed document.
CanvasPrinter
  canvas : CanvasComponent
The canvas to print.
CanvasPrinter
  centerContent : Boolean
Whether to center the printed content within the printable area.
CanvasPrinter
  hPages : Number
The number of page rows to use for multi page printing.
CanvasPrinter
  margin : Rectangle
A margin that is added between the printable bounds and the printed content.
CanvasPrinter
  printAsBitmap : Boolean
Whether to use bitmap printing.
CanvasPrinter
  printRectangle : Rectangle
The portion of the canvas that will be printed, in world coordinates.
CanvasPrinter
  scaleDownToFit : Boolean
Whether to scale the printed content down to fit the printable area, if the content is larger than the printable area.
CanvasPrinter
  scaleUpToFit : Boolean
Whether to scale the printed content up to fit the printable area, if the content is smaller than the printable area.
CanvasPrinter
  vPages : Number
The number of page columns to use for multi page printing.
CanvasPrinter
Public Methods
 MethodDefined By
  
Initializes a new instance.
CanvasPrinter
  
print(canvasSprite:Sprite = null):void
Print the contents of the canvas, using the properties set on this instance.
CanvasPrinter
Protected Methods
 MethodDefined By
  
Callback that is invoked after the PrintJob has been started, but before any pages have been added.
CanvasPrinter
  
drawPageBackground(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle):void
Draws the background color, if one was specified.
CanvasPrinter
  
drawPageContent(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle, canvasSprite:Sprite):void
Adds the canvas contents to the current print sprite.
CanvasPrinter
  
drawPageForeground(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle):void
Callback that allows to draw decorations on top of the canvas contents.
CanvasPrinter
  
Callback that is invoked after all pages have been added to the PrintJob, but before the PrintJob is sent.
CanvasPrinter
  
Callback method during an addPrintPage call that determines the rectangle to print on the given page.
CanvasPrinter
  
Calculates the scale factor that will be applied to the canvas contents for printing, given the current properties of this instance and the page size.
CanvasPrinter
  
handlePrintError(ctx:ICanvasPrintContext, error:Error):void
Called when an Error occurs during printing.
CanvasPrinter
  
Called after the user closed a print dialog by selecting cancel.
CanvasPrinter
  
printCore(canvasSprite:Sprite):void
CanvasPrinter
Property Detail
backgroundColorproperty
backgroundColor:*

The color that will be used to fill the background of the printed document.

If no background color is specified, some Flash Player versions will use a default grayish background color. Therefore, the default value is white.

If this property is set to null, no background will be drawn.

The default value is 0xFFFFFF.

This property can be used as the source for data binding.


Implementation
    public function get backgroundColor():*
    public function set backgroundColor(value:any):void
canvasproperty 
canvas:CanvasComponent

The canvas to print.

This property can be used as the source for data binding.


Implementation
    public function get canvas():CanvasComponent
    public function set canvas(value:CanvasComponent):void
centerContentproperty 
centerContent:Boolean

Whether to center the printed content within the printable area.

This property can be used as the source for data binding.


Implementation
    public function get centerContent():Boolean
    public function set centerContent(value:Boolean):void
hPagesproperty 
hPages:Number

The number of page rows to use for multi page printing.

This property can be used as the source for data binding.


Implementation
    public function get hPages():Number
    public function set hPages(value:Number):void
marginproperty 
margin:Rectangle

A margin that is added between the printable bounds and the printed content.

If multiple pages are printed, the margin will not be added to each individual page, but to the combined printable area.

This property can be used as the source for data binding.


Implementation
    public function get margin():Rectangle
    public function set margin(value:Rectangle):void
printAsBitmapproperty 
printAsBitmap:Boolean

Whether to use bitmap printing.

This property can be used as the source for data binding.


Implementation
    public function get printAsBitmap():Boolean
    public function set printAsBitmap(value:Boolean):void

See also

flash.printing.PrintJobOptions.printAsBitmap
printRectangleproperty 
printRectangle:Rectangle

The portion of the canvas that will be printed, in world coordinates.

This property can be used as the source for data binding.


Implementation
    public function get printRectangle():Rectangle
    public function set printRectangle(value:Rectangle):void
scaleDownToFitproperty 
scaleDownToFit:Boolean

Whether to scale the printed content down to fit the printable area, if the content is larger than the printable area.

This property can be used as the source for data binding.


Implementation
    public function get scaleDownToFit():Boolean
    public function set scaleDownToFit(value:Boolean):void
scaleUpToFitproperty 
scaleUpToFit:Boolean

Whether to scale the printed content up to fit the printable area, if the content is smaller than the printable area.

This property can be used as the source for data binding.


Implementation
    public function get scaleUpToFit():Boolean
    public function set scaleUpToFit(value:Boolean):void
vPagesproperty 
vPages:Number

The number of page columns to use for multi page printing.

This property can be used as the source for data binding.


Implementation
    public function get vPages():Number
    public function set vPages(value:Number):void
Constructor Detail
CanvasPrinter()Constructor
public function CanvasPrinter(canvas:CanvasComponent = null)

Initializes a new instance.

If a canvas instance is provided, this method will set the printRect to the current value of the canvas' contentRect property. If no canvas is provided upon initialization, the canvas property has to be set before calling print().

Parameters
canvas:CanvasComponent (default = null) — The canvas. If null, the canvas property has to be set before calling print().
Method Detail
beginPrint()method
protected function beginPrint(ctx:ICanvasPrintContext):void

Callback that is invoked after the PrintJob has been started, but before any pages have been added.

If no canvas has been set, this implementation will cancel printing.

Parameters

ctx:ICanvasPrintContext — The current print context.

drawPageBackground()method 
protected function drawPageBackground(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle):void

Draws the background color, if one was specified.

This function is called for every page that is printed.

Parameters

ctx:ICanvasPrintContext
 
printSprite:Sprite
 
pagePrintBounds:Rectangle

drawPageContent()method 
protected function drawPageContent(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle, canvasSprite:Sprite):void

Adds the canvas contents to the current print sprite.

A pre-calculated Sprite containing a copy of the canvas object tree can be passed to support the printing of lazy-loading image data.

This function is called for every page that is printed.

Parameters

ctx:ICanvasPrintContext
 
printSprite:Sprite
 
pagePrintBounds:Rectangle
 
canvasSprite:Sprite

See also

drawPageForeground()method 
protected function drawPageForeground(ctx:ICanvasPrintContext, printSprite:Sprite, pagePrintBounds:Rectangle):void

Callback that allows to draw decorations on top of the canvas contents.

This function is called for every page that is printed.

Parameters

ctx:ICanvasPrintContext
 
printSprite:Sprite
 
pagePrintBounds:Rectangle

endPrint()method 
protected function endPrint(ctx:ICanvasPrintContext):void

Callback that is invoked after all pages have been added to the PrintJob, but before the PrintJob is sent.

Parameters

ctx:ICanvasPrintContext — The current print context.

getPagePrintBounds()method 
protected function getPagePrintBounds(ctx:ICanvasPrintContext):Rectangle

Callback method during an addPrintPage call that determines the rectangle to print on the given page.

Parameters

ctx:ICanvasPrintContext

Returns
Rectangle
getScale()method 
protected function getScale(ctx:ICanvasPrintContext):Number

Calculates the scale factor that will be applied to the canvas contents for printing, given the current properties of this instance and the page size.

Parameters

ctx:ICanvasPrintContext

Returns
Number
handlePrintError()method 
protected function handlePrintError(ctx:ICanvasPrintContext, error:Error):void

Called when an Error occurs during printing. The default implementation shows an Alert window.

Parameters

ctx:ICanvasPrintContext
 
error:Error

print()method 
public function print(canvasSprite:Sprite = null):void

Print the contents of the canvas, using the properties set on this instance.

A pre-calculated Sprite containing a copy of the canvas object tree can be passed optionally.

If no printRectangle has been set, this implementation will set the printRectangle to the current value of the canvas' contentRect. If no canvas is set, either, an error will be thrown.

Parameters

canvasSprite:Sprite (default = null) — A pre-calculated canvas Sprite. If no sprite is passed, CanvasComponent#createSprite() is used to create the sprite that will be printed.

See also

printCanceled()method 
protected function printCanceled():void

Called after the user closed a print dialog by selecting cancel.

printCore()method 
protected function printCore(canvasSprite:Sprite):void

Parameters

canvasSprite:Sprite