Packageorg.alivepdf.pdf
Classpublic final class PDF
Implementsflash.events.IEventDispatcher

The PDF class represents a PDF document.



Public Properties
 PropertyDefined by
  totalPages : int
[read-only] Lets you retrieve the number of pages in the PDF document
PDF
Public Methods
 MethodDefined by
  
PDF(orientation:String = "Portrait", unit:String = "Mm", pageSize:Object = null, rotation:int = 0)
The PDF class represents a PDF document.
PDF
  
addBookmark(text:String, level:int, y:Number, color:RGBColor):void
Lets you add a bookmark
PDF
  
addCell(width:Number = 0, height:Number = 0, text:String = "", border:Number = 0, ln:String = "0", align:Number, fill:String = "0", link:*):void
Add a cell with some text to the current page
PDF
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
PDF
  
addImage(displayObject:DisplayObject, x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0, imageFormat:String = "JPG", quality:Number = 100, alpha:Number = 1, resizeMode:String = "None", blendMode:String = "Normal", keepTransformation:Boolean = true, link:String = ""):void
The addImage method takes an incoming DisplayObject.
PDF
  
addImageStream(imageBytes:ByteArray, x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0, alpha:Number = 1, resizeMode:String = "None", blendMode:String = "Normal", keepTransformation:Boolean = true, link:String = ""):void
The addImageStream method takes an incoming image as a ByteArray.
PDF
  
addLink(x:Number, y:Number, width:Number, height:Number, link:String, highlight:* = I):void
Lets you add clickable link to a specific position
PDF
  
addMultiCell(width:Number, height:Number, text:String, border:String = "0", align:int = J, filled:* = 0):void
Add a multicell with some text to the current page
PDF
  
addPage(page:Page = null):Page
Lets you add a page to the current PDF
PDF
  
addText(text:String, x:Number = 0, y:Number = 0):void
Lets you set some text to any position on the page
PDF
  
addTextNote(x:Number, y:Number, width:Number, height:Number, text:String = "A note !"):void
Lets you add a text annotation to the current page
PDF
  
addTransition(style:String = "R", duration:Number = 1, dimension:String = "H", motionDirection:String = "I", transitionDirection:int = 0):void
Lets you add a transition between each PDF page Note : PDF must be shown in fullscreen to see the transitions, use the setDisplayMode method with the PageMode.FULL_SCREEN parameter
PDF
  
beginFill(color:Color):void
Sets the filling color for different color spaces CMYK/RGB/DEVICEGRAY
PDF
  
curveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, finalX3:Number, finalY3:Number):void
The curveTo method draws a cubic bezier curve
PDF
  
dispatchEvent(event:Event):Boolean
PDF
  
drawCircle(x:Number, y:Number, radius:Number):void
The drawCircle method draws a circle
PDF
  
drawEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number):void
The drawEllipse method draws an ellipse
PDF
  
drawPolygone(points:Array):void
The drawPolygone method draws a polygone
PDF
  
drawRect(rect:Rectangle):void
The drawRect method draws a rectangle shape
PDF
  
drawRoundRect(rect:Rectangle, ellipseWidth:Number):void
The drawRoundedRect method draws a rounded rectangle shape
PDF
  
end():void
The end method closes the stroke
PDF
  
endFill():void
Ends all previous filling
PDF
  
Lets you retrieve the current Page
PDF
  
Returns the default PDF orientation
PDF
  
Returns the default PDF Size
PDF
  
getDefaultUnit():String
Returns the default PDF unit unit
PDF
  
getMargins():Rectangle
Lets you retrieve the margins dimensions
PDF
  
getPage(page:int):Page
Lets you retrieve a Page object
PDF
  
getPages():Array
Lets you retrieve all the PDF pages
PDF
  
getX():Number
Lets you retrieve the X position for the current page
PDF
  
getY():Number
Lets you retrieve the Y position for the current page
PDF
  
gotoPage(page:int):void
Lets you move to a Page in the PDF
PDF
  
hasEventListener(type:String):Boolean
PDF
  
lineStyle(color:Color, thickness:Number = 1, flatness:Number = 0, alpha:Number = 1, blendMode:String = "Normal", style:DashedLine = null, caps:String = null, joints:String = null, miterLimit:Number = 3):void
Sets the stroke style
PDF
  
lineTo(x:Number, y:Number):void
Lets you draw a stroke from the current point to the new point
PDF
  
moveTo(x:Number, y:Number):void
Lets you move the current drawing point to the specified destination
PDF
  
newLine(height:*):void
Lets you insert a line break for text
PDF
  
Lets you remove all the pages from the PDF
PDF
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
PDF
  
removePage(page:int):Page
Lets you remove a Page from the PDF
PDF
  
rotatePage(number:int, rotation:Number):void
Lets you rotate a specific page (between 1 and n-1)
PDF
  
save(method:String, url:String = "", downloadMethod:String = "inline", fileName:String = "generated.pdf"):*
PDF
  
setAliasNbPages(alias:String = "{nb}"):void
Lets you specify an alias for the total number of pages
PDF
  
setAlpha(alpha:Number, blendMode:String = "Normal"):void
Lets you specify the opacity for the next drawing operations, from 0 (100% transparent) to 1 (100% opaque)
PDF
  
setAuthor(author:String):void
Sets the specified author for the PDF
PDF
  
setAutoPageBreak(auto:Boolean, margin:Number):void
Lets you enable or disable auto page break mode and triggering margin
PDF
  
setBottomMargin(margin:Number):void
Lets you specify the bottom margin
PDF
  
setCreator(creator:String):void
Sets the specified creator for the PDF
PDF
  
setDisplayMode(zoom:String = "FullWidth", layout:String = "SinglePage", mode:String = "UseNone"):void
Lets you set a specific display mode, the DisplayMode takes care of the general layout of the PDF in the PDF reader
PDF
  
setFont(family:String, style:String = "", size:int = 0):void
Lets you set a specific font
PDF
  
setFontSize(size:int):void
Lets you set a new size for the current font
PDF
  
setKeywords(keywords:String):void
Sets the specified keywords for the PDF
PDF
  
setLeftMargin(margin:Number):void
Lets you specify the left margin
PDF
  
setMargins(left:Number, top:Number, right:Number = -1, bottom:Number = 20):void
Lets you specify the left, top, and right margins
PDF
  
setRightMargin(margin:Number):void
Lets you specify the right margin
PDF
  
setSubject(subject:String):void
Lets you set a subject for the PDF
PDF
  
setTitle(title:String):void
Lets you set a title for the PDF
PDF
  
setTopMargin(margin:Number):void
Lets you specify the top margin
PDF
  
setUnit(unit:String):String
PDF
  
setViewerPreferences(toolbar:String = "false", menubar:String = "false", windowUI:String = "false", fitWindow:String = "false", centeredWindow:String = "false", displayTitle:String = "false"):void
Lets you control the way the document is to be presented on the screen or in print.
PDF
  
setX(x:Number):void
Lets you specify the X position for the current page
PDF
  
setXY(x:Number, y:Number):void
Lets you specify the X and Y position for the current page
PDF
  
setY(y:Number):void
Lets you specify the Y position for the current page
PDF
  
textStyle(color:Color, alpha:Number = 1, rendering:int = 0, wordSpace:Number = 0, characterSpace:Number = 0, scale:Number = 100, leading:Number = 0):void
Sets the text style
PDF
  
toString():String
PDF
  
willTrigger(type:String):Boolean
PDF
  
writeText(lineHeight:Number, text:String, link:String = ""):void
Lets you write some text
PDF
Events
 EventSummaryDefined by
   Dispatched when a page has been added to the PDF.PDF
   Dispatched when PDF has been generated and available.PDF
   Dispatched when the PDF page tree has been generated.PDF
   Dispatched when the required resources (fonts, images, etc.) haven been written into the PDF.PDF
   Dispatched when the PDF generation has been initiated.PDF
Property detail
totalPagesproperty
totalPages:int  [read-only]

Lets you retrieve the number of pages in the PDF document

Implementation
    public function get totalPages():int

Example
This example shows how to retrieve the number of pages :
    var totalPages:int = myPDF.getPageCount ();
  

Constructor detail
PDF()constructor
public function PDF(orientation:String = "Portrait", unit:String = "Mm", pageSize:Object = null, rotation:int = 0)

The PDF class represents a PDF document.

Parameters
orientation:String (default = "Portrait")
 
unit:String (default = "Mm")
 
pageSize:Object (default = null)
 
rotation:int (default = 0)

Example
This example shows how to create a valid PDF document :
    var myPDF:PDF = new PDF ( Orientation.PORTRAIT, Unit.MM, Size.A4 );
  

Method detail
addBookmark()method
public function addBookmark(text:String, level:int, y:Number, color:RGBColor):void

Lets you add a bookmark

Parameters
text:String — Text appearing in the outline panel
 
level:int — Specify the bookmark's level
 
y:Number — Position in the current page to go
 
color:RGBColor — Red offset for the text color

Example
This example shows how to add a bookmark for the current page :
    myPDF.addBookmark("A bookmark", 0, 0, 0, .9, 0);
  myPDF.addPage();
  myPDF.addBookmark("Another bookmark", 0, 60, .9, .9, 0);
  

addCell()method 
public function addCell(width:Number = 0, height:Number = 0, text:String = "", border:Number = 0, ln:String = "0", align:Number, fill:String = "0", link:*):void

Add a cell with some text to the current page

Parameters
width:Number (default = 0) — Cell width
 
height:Number (default = 0) — Cell height
 
text:String (default = "") — Text to add into the cell
 
border:Number (default = 0) — Sets the new position after cell is drawn, default value is 0
 
ln:String (default = "0") — Lets you center or align the text into the cell
 
align:Number — Lets you specify if the cell is colored (1) or transparent (0)
 
fill:String (default = "0") — Any http link, like http://www.mylink.com
 
link:*

Example
This example shows how to write some text within a cell :
    myPDF.setFont(FontFamily.HELVETICA, 'B', 12);
  myPDF.textStyle ( new RGBColor ( 0x990000 ) );
  myPDF.addCell(50,10,'Some text into a cell !',1,1);
  
This example shows how to write some clikable text within a cell :
    myPDF.setFont(FontFamily.HELVETICA, 'B', 12);
  myPDF.textStyle ( new RGBColor ( 0x990000 ) );
  myPDF.addCell(50,10,'A clikable cell !', 1, 1, null, 0, "http://www.alivepdf.org");
  

addEventListener()method 
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
 
useWeakReference:Boolean (default = false)
addImage()method 
public function addImage(displayObject:DisplayObject, x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0, imageFormat:String = "JPG", quality:Number = 100, alpha:Number = 1, resizeMode:String = "None", blendMode:String = "Normal", keepTransformation:Boolean = true, link:String = ""):void

The addImage method takes an incoming DisplayObject. A JPG snapshot is done and included in the PDF document

Parameters
displayObject:DisplayObject
 
x:Number (default = 0)
 
y:Number (default = 0)
 
width:Number (default = 0)
 
height:Number (default = 0)
 
imageFormat:String (default = "JPG")
 
quality:Number (default = 100)
 
alpha:Number (default = 1)
 
resizeMode:String (default = "None")
 
blendMode:String (default = "Normal")
 
keepTransformation:Boolean (default = true)
 
link:String (default = "")

Example
This example shows how to add a 100% compression quality JPG image into the current page at a position of 0,0 with no resizing behavior :
      myPDF.addImage ( displayObject, 0, 0, 0, 0, ImageFormat.JPG, 100, .2 );
   

addImageStream()method 
public function addImageStream(imageBytes:ByteArray, x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0, alpha:Number = 1, resizeMode:String = "None", blendMode:String = "Normal", keepTransformation:Boolean = true, link:String = ""):void

The addImageStream method takes an incoming image as a ByteArray. This method can be used to embed high-quality images (300 dpi) to the PDF

Parameters
imageBytes:ByteArray
 
x:Number (default = 0)
 
y:Number (default = 0)
 
width:Number (default = 0)
 
height:Number (default = 0)
 
alpha:Number (default = 1)
 
resizeMode:String (default = "None")
 
blendMode:String (default = "Normal")
 
keepTransformation:Boolean (default = true)
 
link:String (default = "")

Example
This example shows how to add an image as a ByteArray into the current page with a page resize behavior :
      myPDF.addImageStream( bytes, 0, 0, 0, 0, 1, ImageResize.RESIZE_PAGE );
   

addLink()method 
public function addLink(x:Number, y:Number, width:Number, height:Number, link:String, highlight:* = I):void

Lets you add clickable link to a specific position

Parameters
x:Number — Page Format, can be Size.A3, Size.A4, Size.A5, Size.LETTER or Size.LEGAL
 
y:Number
 
width:Number
 
height:Number
 
link:String
 
highlight:* (default = I)

Example
This example shows how to add an invisible clickable link in the current page :
    myPDF.addLink ( 70, 4, 60, 16, "http://www.alivepdf.org");
  

addMultiCell()method 
public function addMultiCell(width:Number, height:Number, text:String, border:String = "0", align:int = J, filled:* = 0):void

Add a multicell with some text to the current page

Parameters
width:Number — Cell width
 
height:Number — Cell height
 
text:String — Text to add into the cell
 
border:String (default = "0") — Lets you specify if a border should be drawn around the cell
 
align:int (default = J) — Lets you center or align the text into the cell, values can be L (left align), C (centered), R (right align), J (justified) default value
 
filled:* (default = 0) — Lets you specify if the cell is colored (1) or transparent (0)

Example
This example shows how to write a table made of text cells :
    myPDF.setFont( FontFamily.COURIER, Style.BOLD, 14 );
  myPDF.textStyle ( new RGBColor ( 0x990000 ) );
  myPDF.addMultiCell ( 70, 24, "A multicell :)", 1);
  myPDF.addMultiCell ( 70, 24, "A multicell :)", 1);
  

addPage()method 
public function addPage(page:Page = null):Page

Lets you add a page to the current PDF

Parameters
page:Page (default = null)

Returns
Page

Example
This example shows how to add an A4 page with a landscape orientation :
      var page:Page = new Page ( Orientation.LANDSCAPE, Unit.MM, Size.A4 );
   myPDF.addPage( page );
   
This example shows how to add a page with a custom size :
      var customSize:Size = new Size ( [420.94, 595.28], "CustomSize", [5.8,  8.3], [148, 210] );
   var page:Page = new Page ( Orientation.PORTRAIT, Unit.MM, customSize );
   myPDF.addPage ( page );
   

addText()method 
public function addText(text:String, x:Number = 0, y:Number = 0):void

Lets you set some text to any position on the page

Parameters
text:String — The text to add
 
x:Number (default = 0) — X position
 
y:Number (default = 0) — Y position

Example
This example shows how to set some text to a specific place :
    myPDF.addText ('Cubic Bezier curve with curveTo', 14, 110);
  

addTextNote()method 
public function addTextNote(x:Number, y:Number, width:Number, height:Number, text:String = "A note !"):void

Lets you add a text annotation to the current page

Parameters
x:Number — Note X position
 
y:Number — Note Y position
 
width:Number — Note width
 
height:Number — Note height
 
text:String (default = "A note !") — Text for the note

Example
This example shows how to add a note annotation in the current page :
    myPDF.addNote (100, 75, 50, 50, "A note !");
  

addTransition()method 
public function addTransition(style:String = "R", duration:Number = 1, dimension:String = "H", motionDirection:String = "I", transitionDirection:int = 0):void

Lets you add a transition between each PDF page Note : PDF must be shown in fullscreen to see the transitions, use the setDisplayMode method with the PageMode.FULL_SCREEN parameter

Parameters
style:String (default = "R") — Transition style, can be Transition.SPLIT, Transition.BLINDS, BLINDS.BOX, Transition.WIPE, etc.
 
duration:Number (default = 1) — The transition duration
 
dimension:String (default = "H") — The dimension in which the the specified transition effect occurs
 
motionDirection:String (default = "I") — The motion's direction for the specified transition effect
 
transitionDirection:int (default = 0) — The direction in which the specified transition effect moves

Example
This example shows how to add a 4 seconds "Wipe" transition between the first and second page :
  myPDF.addTransition (Transition.WIPE, 4, Dimension.VERTICAL);   
  myPDF.addPage();  
  myPDF.addTransition (Transition.WIPE, 4, Dimension.VERTICAL);
  

beginFill()method 
public function beginFill(color:Color):void

Sets the filling color for different color spaces CMYK/RGB/DEVICEGRAY

Parameters
color:Color — Color object, can be CMYKColor, GrayColor, or RGBColor

Example
This example shows how to create a red rectangle in the current page :
    myPDF.beginFill ( new RGBColor ( 0x990000 ) );
  myPDF.drawRect ( new Rectangle ( 10, 26, 50, 25 ) );
  

curveTo()method 
public function curveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, finalX3:Number, finalY3:Number):void

The curveTo method draws a cubic bezier curve

Parameters
controlX1:Number
 
controlY1:Number
 
controlX2:Number
 
controlY2:Number
 
finalX3:Number
 
finalY3:Number

Example
This example shows how to draw some curves lines in the current page :
Important : Always call the end() method when you're done
    myPDF.lineStyle ( new RGBColor ( 0x990000 ), 1, 1, null, CapsStyle.NONE, JointStyle.MITER );
  myPDF.moveTo ( 10, 200 );
  myPDF.curveTo ( 120, 210, 196, 280, 139, 195 );
  myPDF.curveTo ( 190, 110, 206, 190, 179, 205 );
  myPDF.end();
  

dispatchEvent()method 
public function dispatchEvent(event:Event):BooleanParameters
event:Event

Returns
Boolean
drawCircle()method 
public function drawCircle(x:Number, y:Number, radius:Number):void

The drawCircle method draws a circle

Parameters
x:Number — X Position
 
y:Number — Y Position
 
radius:Number — Circle Radius

Example
This example shows how to create a rounded red ellipse in the current page :
    myPDF.beginFill ( new RGBColor ( 0x990000 ) );
  myPDF.drawCircle ( 30, 180, 20 );
  

drawEllipse()method 
public function drawEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number):void

The drawEllipse method draws an ellipse

Parameters
x:Number — X Position
 
y:Number — Y Position
 
radiusX:Number — X Radius
 
radiusY:Number — Y Radius

Example
This example shows how to create a rounded red ellipse in the current page :
    myPDF.lineStyle ( new RGBColor ( 0x990000 ), 1, .3, new DashedLine ([0, 1, 2, 6]), CapsStyle.NONE, JointStyle.ROUND );
  myPDF.beginFill ( new RGBColor ( 0x990000 ) );
  myPDF.drawEllipse( 45, 275, 40, 15 );
  

drawPolygone()method 
public function drawPolygone(points:Array):void

The drawPolygone method draws a polygone

Parameters
points:Array — Array of points

Example
This example shows how to create a polygone with a few points :
    myPDF.beginFill ( new RGBColor ( 0x990000 ) );
  myPDF.drawPolygone ( [89, 40, 20, 90, 40, 50, 10, 60, 70, 90] );
  

drawRect()method 
public function drawRect(rect:Rectangle):void

The drawRect method draws a rectangle shape

Parameters
rect:Rectangle — A flash.geom.Rectange object

Example
This example shows how to create a blue rectangle in the current page :
    myPDF.lineStyle ( new RGBColor ( 0x990000 ), 1, .3, null, CapsStyle.ROUND, JointStyle.MITER );
  myPDF.beginFill ( new RGBColor ( 0x009900 ) );
  myPDF.drawRect ( new Rectangle ( 20, 46, 100, 45 ) );
  

drawRoundRect()method 
public function drawRoundRect(rect:Rectangle, ellipseWidth:Number):void

The drawRoundedRect method draws a rounded rectangle shape

Parameters
rect:Rectangle — A flash.geom.Rectange object
 
ellipseWidth:Number — Angle radius

Example
This example shows how to create a rounded green rectangle in the current page :
    myPDF.lineStyle ( new RGBColor ( 0x00FF00 ), 1, 0, .3, BlendMode.NORMAL, null, CapsStyle.ROUND, JointStyle.MITER );
  myPDF.beginFill ( new RGBColor ( 0x009900 ) );
  myPDF.drawRoundRect ( new Rectangle ( 20, 46, 100, 45 ), 20 );
  

end()method 
public function end():void

The end method closes the stroke


Example
This example shows how to draw some dashed lines in the current page with specific caps style and joint style :
Important : Always call the end() method when you're done
  
  myPDF.lineStyle( new RGBColor ( 0x990000 ), 1, 1 );
  myPDF.moveTo ( 10, 20 );
  myPDF.lineTo ( 40, 20 );
  myPDF.lineTo ( 40, 40 );
  myPDF.lineTo ( 10, 40 );
  myPDF.lineTo ( 10, 20 );
  // end the stroke
  myPDF.end();
  

endFill()method 
public function endFill():void

Ends all previous filling


Example
This example shows how to create a red rectangle in the current page :
    myPDF.beginFill ( new RGBColor ( 0x990000 ) );
  myPDF.moveTo ( 10, 10 );
  myPDF.lineTo ( 20, 90 );
  myPDF.lineTo ( 90, 50);
  myPDF.end()
  myPDF.endFill();
  

getCurrentPage()method 
public function getCurrentPage():Page

Lets you retrieve the current Page

Returns
Page — Page A Page object

Example
This example shows how to retrieve the current page :
    var page:Page = myPDF.getCurrentPage ();
  

getDefaultOrientation()method 
public function getDefaultOrientation():String

Returns the default PDF orientation

Returns
String — String
getDefaultSize()method 
public function getDefaultSize():Size

Returns the default PDF Size

Returns
Size — Size
getDefaultUnit()method 
public function getDefaultUnit():String

Returns the default PDF unit unit

Returns
String — String
getMargins()method 
public function getMargins():Rectangle

Lets you retrieve the margins dimensions

Returns
Rectangle — Rectangle

Example
This example shows how to get the margins dimensions :
    var marginsDimensions:Rectangle = myPDF.getMargins ();
  // output : (x=10.00, y=10.0012, w=575.27, h=811.88)
  trace( marginsDimensions )
  

getPage()method 
public function getPage(page:int):Page

Lets you retrieve a Page object

Parameters
page:int — page number, from 1 to total numbers of pages

Returns
Page — Page

Example
This example shows how to retrieve the first page :
    var page:Page = myPDF.getPage ( 1 );
  

getPages()method 
public function getPages():Array

Lets you retrieve all the PDF pages

Returns
Array — Array

Example
This example shows how to retrieve all the PDF pages :
    var pdfPages:Array = myPDF.getPages ();
    for each ( var p:in pdfPages ) trace( p );
  
  outputs :
  
  [Page orientation=Portrait width=210 height=297]
  [Page orientation=Landscape width=297 height=210]
  
  

getX()method 
public function getX():Number

Lets you retrieve the X position for the current page

Returns
Number — Number the X position
getY()method 
public function getY():Number

Lets you retrieve the Y position for the current page

Returns
Number — Number the Y position
gotoPage()method 
public function gotoPage(page:int):void

Lets you move to a Page in the PDF

Parameters
page:int — page number, from 1 to total numbers of pages

Example
This example shows how to move to the first page :
    myPDF.gotoPage ( 1 );
  // draw on the first page
  myPDF.lineStyle( new RGBColor(0xFF0000), 2, 0 );
     myPDF.drawRect( 60, 60, 40, 40 ); 
  

hasEventListener()method 
public function hasEventListener(type:String):BooleanParameters
type:String

Returns
Boolean
lineStyle()method 
public function lineStyle(color:Color, thickness:Number = 1, flatness:Number = 0, alpha:Number = 1, blendMode:String = "Normal", style:DashedLine = null, caps:String = null, joints:String = null, miterLimit:Number = 3):void

Sets the stroke style

Parameters
color:Color
 
thickness:Number (default = 1)
 
flatness:Number (default = 0)
 
alpha:Number (default = 1)
 
blendMode:String (default = "Normal")
 
style:DashedLine (default = null)
 
caps:String (default = null)
 
joints:String (default = null)
 
miterLimit:Number (default = 3)

Example
This example shows how to set a specific stroke style :
    myPDF.lineStyle ( new RGBColor ( 0x990000 ), 1, 0, 1, null, Caps.NONE, Joint.MITER );
  

lineTo()method 
public function lineTo(x:Number, y:Number):void

Lets you draw a stroke from the current point to the new point

Parameters
x:Number — X position
 
y:Number — Y position

Example
This example shows how to draw some dashed lines in the current page with specific caps style and joint style :
Important : Always call the end() method when you're done
    myPDF.lineStyle( new RGBColor ( 0x990000 ), 1, 1 );
  myPDF.moveTo ( 10, 20 );
  myPDF.lineTo ( 40, 20 );
  myPDF.lineTo ( 40, 40 );
  myPDF.lineTo ( 10, 40 );
  myPDF.lineTo ( 10, 20 );
  myPDF.end();
  

moveTo()method 
public function moveTo(x:Number, y:Number):void

Lets you move the current drawing point to the specified destination

Parameters
x:Number — X position
 
y:Number — Y position

Example
This example shows how to move the pen to 120,200 :
    myPDF.moveTo ( 120, 200 );
  

newLine()method 
public function newLine(height:*):void

Lets you insert a line break for text

Parameters
height:* — Line break height

Example
This example shows how to add a line break :
    myPDF.newLine ( 10 );
  

removeAllPages()method 
public function removeAllPages():void

Lets you remove all the pages from the PDF


Example
This example shows how to remove all the pages :
  myPDF.removeAllPages();
  

removeEventListener()method 
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
removePage()method 
public function removePage(page:int):Page

Lets you remove a Page from the PDF

Parameters
page:int — page number, from 1 to total numbers of pages

Returns
Page — Page

Example
This example shows how to remove the first page :
  myPDF.removePage ( 1 );
  
If you want to remove pages each by each, you can combine removePage with getPageCount
  myPDF.removePage ( myPDFEncoder.getPageCount() );
  

rotatePage()method 
public function rotatePage(number:int, rotation:Number):void

Lets you rotate a specific page (between 1 and n-1)

Parameters
number:int — Page number
 
rotation:Number — Page rotation (must be a multiple of 90)

Throws

Example
This example shows how to rotate the first page 90 clock wise :
    myPDF.rotatePage ( 1, 90 );
  
This example shows how to rotate the first page 90 counter clock wise :
    myPDF.rotatePage ( 1, -90 );
  

save()method 
public function save(method:String, url:String = "", downloadMethod:String = "inline", fileName:String = "generated.pdf"):*

Parameters
method:String — Can be se to Method.LOCAL, the savePDF will return the PDF ByteArray. When Method.REMOTE is passed, just specify the path to the create.php file
 
url:String (default = "") — The url of the create.php file
 
downloadMethod:String (default = "inline") — Lets you specify the way the PDF is going to be available. Use Download.INLINE if you want the PDF to be opened in the browser, use Download.ATTACHMENT if you want to make it available with a save-as dialog box
 
fileName:String (default = "generated.pdf") — The name of the PDF, only available when Method.REMOTE is used

Returns
* — The ByteArray PDF when Method.LOCAL is used, otherwise the method returns null

Example
This example shows how to save the PDF on the desktop with the AIR runtime :
    var f:FileStream = new FileStream();
       file = File.desktopDirectory.resolvePath("generate.pdf");
       f.open( file, FileMode.WRITE);
       var bytes:ByteArray = myPDF.save( Method.LOCAL );
       f.writeBytes(bytes);
       f.close(); 
  
This example shows how to save the PDF through a download dialog-box with Flash or Flex :
    myPDF.save( Method.REMOTE, "http://localhost/save.php", Download.ATTACHMENT );
  
This example shows how to view the PDF in the browser with Flash or Flex :
    myPDF.save( Method.REMOTE, "http://localhost/save.php", Download.INLINE );
  

setAliasNbPages()method 
public function setAliasNbPages(alias:String = "{nb}"):void

Lets you specify an alias for the total number of pages

Parameters
alias:String (default = "{nb}") — Alias to use

Example
This example shows how to show the total number of pages :
    myPDF.setAliasNbPages ( "[nb]" );
  myPDF.textStyle( new RGBColor (0,0,0), 1 );
  myPDF.setFont( FontFamily.HELVETICA, Style.NORMAL, 18 );
  // then use the alias when needed
  myPDF.addText ("There are [nb] pages in the PDF !", 150, 50);
  

setAlpha()method 
public function setAlpha(alpha:Number, blendMode:String = "Normal"):void

Lets you specify the opacity for the next drawing operations, from 0 (100% transparent) to 1 (100% opaque)

Parameters
alpha:Number — Opacity
 
blendMode:String (default = "Normal") — Blend mode, can be Blend.DIFFERENCE, BLEND.HARDLIGHT, etc.

Example
This example shows how to set the transparency to 50% for any following drawing, image or text operation :
    myPDF.setAlpha ( .5 );
  

setAuthor()method 
public function setAuthor(author:String):void

Sets the specified author for the PDF

Parameters
author:String — The author

Example
This example shows how to add a specific author to the PDF tags :
    myPDF.setAuthor ( "Bob" );
  

setAutoPageBreak()method 
public function setAutoPageBreak(auto:Boolean, margin:Number):void

Lets you enable or disable auto page break mode and triggering margin

Parameters
auto:Boolean — Page break mode
 
margin:Number — Bottom margin
setBottomMargin()method 
public function setBottomMargin(margin:Number):void

Lets you specify the bottom margin

Parameters
margin:Number — Bottom margin

Example
This example shows how set bottom margin for the PDF document :
    myPDF.setBottomMargin ( 10 );
  

setCreator()method 
public function setCreator(creator:String):void

Sets the specified creator for the PDF

Parameters
creator:String — Name of the PDF creator

Example
This example shows how to set a creator name to the PDF tags :
    myPDF.setCreator ( "My Application 1.0" );
  

setDisplayMode()method 
public function setDisplayMode(zoom:String = "FullWidth", layout:String = "SinglePage", mode:String = "UseNone"):void

Lets you set a specific display mode, the DisplayMode takes care of the general layout of the PDF in the PDF reader

Parameters
zoom:String (default = "FullWidth") — Zoom mode, can be Display.FULL_PAGE, Display.FULL_WIDTH, Display.REAL, Display.DEFAULT
 
layout:String (default = "SinglePage") — Layout of the PDF document, can be Layout.SINGLE_PAGE, Layout.ONE_COLUMN, Layout.TWO_COLUMN_LEFT, Layout.TWO_COLUMN_RIGHT
 
mode:String (default = "UseNone") — PageMode can be pageMode.USE_NONE, PageMode.USE_OUTLINES, PageMode.USE_THUMBS, PageMode.FULL_SCREEN

Example
This example creates a PDF which opens at full page scaling, one page at a time :
    myPDF.setDisplayMode (Display.FULL_PAGE, Layout.SINGLE_PAGE);
  
To create a full screen PDF you would write :
  
  myPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE, PageMode.FULLSCREEN );
  

setFont()method 
public function setFont(family:String, style:String = "", size:int = 0):void

Lets you set a specific font

Parameters
family:String — Font family, can be any of FontFamily.COURIER, FontFamily.HELVETICA, FontFamily.ARIAL, FontFamily.TIMES, FontFamily.SYMBOL, FontFamily.ZAPFDINGBATS.
 
style:String (default = "") — Any font style, can be Style.BOLD, Style.ITALIC, Style.BOLD_ITALIC, Style.NORMAL
 
size:int (default = 0)

Example
This example shows how to set the Helvetica font, with a bold style :
    myPDF.setFont( FontFamily.HELVETICA, Style.BOLD );
  

setFontSize()method 
public function setFontSize(size:int):void

Lets you set a new size for the current font

Parameters
size:int — Font size

Example
This example shows how to se the current font to 18 :
    myPDF.setFontSize( 18 );
  

setKeywords()method 
public function setKeywords(keywords:String):void

Sets the specified keywords for the PDF

Parameters
keywords:String — The keywords

Example
This example shows how to add some keywords to the PDF tags :
    myPDF.setKeywords ( "Design, Agency, Communication, etc." );
  

setLeftMargin()method 
public function setLeftMargin(margin:Number):void

Lets you specify the left margin

Parameters
margin:Number — Left margin

Example
This example shows how set left margin for the PDF document :
    myPDF.setLeftMargin ( 10 );
  

setMargins()method 
public function setMargins(left:Number, top:Number, right:Number = -1, bottom:Number = 20):void

Lets you specify the left, top, and right margins

Parameters
left:Number — Left margin
 
top:Number — Right number
 
right:Number (default = -1) — Top number
 
bottom:Number (default = 20) — Bottom number

Example
This example shows how to set margins for the PDF document :
    myPDF.setMargins ( 10, 10, 10, 10 );
  

setRightMargin()method 
public function setRightMargin(margin:Number):void

Lets you specify the right margin

Parameters
margin:Number — Right margin

Example
This example shows how set right margin for the PDF document :
    myPDF.setRightMargin ( 10 );
  

setSubject()method 
public function setSubject(subject:String):void

Lets you set a subject for the PDF

Parameters
subject:String — The subject

Example
This example shows how to set a specific subject to the PDF tags :
    myPDF.setSubject ( "Any topic" );
  

setTitle()method 
public function setTitle(title:String):void

Lets you set a title for the PDF

Parameters
title:String — The title

Example
This example shows how to set a specific title to the PDF tags :
    myPDF.setTitle ( "AlivePDF !" );
  

setTopMargin()method 
public function setTopMargin(margin:Number):void

Lets you specify the top margin

Parameters
margin:Number — Top margin

Example
This example shows how set top margin for the PDF document :
    myPDF.setTopMargin ( 10 );
  

setUnit()method 
public function setUnit(unit:String):StringParameters
unit:String

Returns
String
setViewerPreferences()method 
public function setViewerPreferences(toolbar:String = "false", menubar:String = "false", windowUI:String = "false", fitWindow:String = "false", centeredWindow:String = "false", displayTitle:String = "false"):void

Lets you control the way the document is to be presented on the screen or in print.

Parameters
toolbar:String (default = "false") — Toolbar behavior
 
menubar:String (default = "false") — Menubar behavior
 
windowUI:String (default = "false") — WindowUI behavior
 
fitWindow:String (default = "false") — Specify whether to resize the document's window to fit the size of the first displayed page.
 
centeredWindow:String (default = "false") — Specify whether to position the document's window in the center of the screen.
 
displayTitle:String (default = "false") — Specify whether the window's title bar should display the document title taken from the value passed to the setTitle method

Example
This example shows how to present the document centered on the screen with no toolbars :
    myPDF.setViewerPreferences (ToolBar.HIDE, MenuBar.HIDE, WindowUI.HIDE, FitWindow.DEFAULT, CenterWindow.CENTERED);
  

setX()method 
public function setX(x:Number):void

Lets you specify the X position for the current page

Parameters
x:Number — The X position
setXY()method 
public function setXY(x:Number, y:Number):void

Lets you specify the X and Y position for the current page

Parameters
x:Number — The X position
 
y:Number — The Y position
setY()method 
public function setY(y:Number):void

Lets you specify the Y position for the current page

Parameters
y:Number — The Y position
textStyle()method 
public function textStyle(color:Color, alpha:Number = 1, rendering:int = 0, wordSpace:Number = 0, characterSpace:Number = 0, scale:Number = 100, leading:Number = 0):void

Sets the text style

Parameters
color:Color — Color object, can be CMYKColor, GrayColor, or RGBColor
 
alpha:Number (default = 1) — Text opacity
 
rendering:int (default = 0) — pRendering Specify the text rendering mode
 
wordSpace:Number (default = 0) — Spaces between each words
 
characterSpace:Number (default = 0) — Spaces between each characters
 
scale:Number (default = 100) — Text scaling
 
leading:Number (default = 0) — Text leading

Example
This example shows how to set a specific black text style with full opacity :
    myPDF.textStyle ( new RGBColor ( 0x000000 ), 1 ); 
  

toString()method 
public function toString():String

Returns
String
willTrigger()method 
public function willTrigger(type:String):BooleanParameters
type:String

Returns
Boolean
writeText()method 
public function writeText(lineHeight:Number, text:String, link:String = ""):void

Lets you write some text

Parameters
lineHeight:Number — Line height, lets you specify height between each lines
 
text:String — Text to write, to put a line break just add a \n in the text string
 
link:String (default = "") — Any link, like http://www.mylink.com, will open te browser when clicked

Example
This example shows how to add some text to the current page :
    myPDF.writeText ( 5, "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", "http://www.google.fr");
  
This example shows how to add some text with a clickable link :
    myPDF.writeText ( 5, "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", "http://www.google.fr");
  

Event detail
addedevent 
Event object type: org.alivepdf.events.PageEvent

Dispatched when a page has been added to the PDF. The addPage() method generate this event


Example
This example shows how to listen for such an event :
    myPDF.addEventListener ( PageEvent.ADDED, pageAdded );
  

completeevent  
Event object type: org.alivepdf.events.ProcessingEvent

Dispatched when PDF has been generated and available. The save() method generate this event


Example
This example shows how to listen for such an event :
    myPDF.addEventListener ( ProcessingEvent.COMPLETE, generationComplete );
  

pageTreeevent  
Event object type: org.alivepdf.events.ProcessingEvent

Dispatched when the PDF page tree has been generated. The save() method generate this event


Example
This example shows how to listen for such an event :
    myPDF.addEventListener ( ProcessingEvent.PAGE_TREE, pageTreeAdded );
  

resourcesevent  
Event object type: org.alivepdf.events.ProcessingEvent

Dispatched when the required resources (fonts, images, etc.) haven been written into the PDF. The save() method generate this event


Example
This example shows how to listen for such an event :
    myPDF.addEventListener ( ProcessingEvent.RESOURCES, resourcesAdded );
  

startedevent  
Event object type: org.alivepdf.events.ProcessingEvent

Dispatched when the PDF generation has been initiated. The save() method generate this event


Example
This example shows how to listen for such an event :
    myPDF.addEventListener ( ProcessingEvent.STARTED, generationStarted );