Package | com.yworks.canvas |
Class | public class CanvasPrinter |
Inheritance | CanvasPrinter flash.events.EventDispatcher |
CanvasComponent
.
Clients can use the various options provided by this class for customizing
the printed output of a CanvasComponent
.
<yworks:CanvasPrinter id="printer" canvas="{graphCanvas}" backgroundColor="0xFFFFFF" />
Property | Defined 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 |
Method | Defined By | ||
---|---|---|---|
CanvasPrinter(canvas:CanvasComponent = null)
Initializes a new instance. | CanvasPrinter | ||
print(canvasSprite:Sprite = null):void
Print the contents of the canvas, using the properties set on this instance. | CanvasPrinter |
Method | Defined By | ||
---|---|---|---|
beginPrint(ctx:ICanvasPrintContext):void
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 | ||
endPrint(ctx:ICanvasPrintContext):void
Callback that is invoked after all pages have been added to the PrintJob,
but before the PrintJob is sent. | CanvasPrinter | ||
getPagePrintBounds(ctx:ICanvasPrintContext):Rectangle
Callback method during an addPrintPage call that determines the
rectangle to print on the given page. | CanvasPrinter | ||
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. | CanvasPrinter | ||
handlePrintError(ctx:ICanvasPrintContext, error:Error):void
Called when an Error occurs during printing. | CanvasPrinter | ||
printCanceled():void
Called after the user closed a print dialog by selecting cancel. | CanvasPrinter | ||
printCore(canvasSprite:Sprite):void | CanvasPrinter |
backgroundColor | property |
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.
public function get backgroundColor():*
public function set backgroundColor(value:any):void
canvas | property |
canvas:CanvasComponent
The canvas to print.
This property can be used as the source for data binding.
public function get canvas():CanvasComponent
public function set canvas(value:CanvasComponent):void
centerContent | property |
centerContent:Boolean
Whether to center the printed content within the printable area.
This property can be used as the source for data binding.
public function get centerContent():Boolean
public function set centerContent(value:Boolean):void
hPages | property |
hPages:Number
The number of page rows to use for multi page printing.
This property can be used as the source for data binding.
public function get hPages():Number
public function set hPages(value:Number):void
margin | property |
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.
public function get margin():Rectangle
public function set margin(value:Rectangle):void
printAsBitmap | property |
printAsBitmap:Boolean
Whether to use bitmap printing.
This property can be used as the source for data binding.
public function get printAsBitmap():Boolean
public function set printAsBitmap(value:Boolean):void
See also
printRectangle | property |
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.
public function get printRectangle():Rectangle
public function set printRectangle(value:Rectangle):void
scaleDownToFit | property |
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.
public function get scaleDownToFit():Boolean
public function set scaleDownToFit(value:Boolean):void
scaleUpToFit | property |
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.
public function get scaleUpToFit():Boolean
public function set scaleUpToFit(value:Boolean):void
vPages | property |
vPages:Number
The number of page columns to use for multi page printing.
This property can be used as the source for data binding.
public function get vPages():Number
public function set vPages(value:Number):void
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()
.
canvas:CanvasComponent (default = null ) — The canvas. If null , the
canvas property has to be set before calling print() .
|
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 |
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 |
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 |
() | 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 |