PdfDocument Class

File
wijmo.pdf.js
Module
wijmo.pdf
Base Class
PdfPageArea
Show
   

Represents a PDF document object, based on PDFKit JavaScript library.

Constructor

Properties

Methods

Events

Constructor

constructor

constructor(options?: any): PdfDocument

Initializes a new instance of the PdfDocument class.

Parameters
Returns
PdfDocument

Properties

bufferPages

Gets a value that indicates whether the pages buffering mode is enabled which means that the document's pages can be iterated over using pageIndex and bufferedPageRange.

This property can be assigned using the PdfDocument constructor only. This property can be set to false only if both header and footer are invisible.

The default value is true.

Type
boolean

compress

Gets a value that indicates whether the document compression is enabled. This property can be assigned using the PdfDocument constructor only.

The default value is true.

Type
boolean

currentPageSettings

Gets an object that represents the current page settings (read-only).

Type
IPdfPageSettings

height

Gets the height of the area, in points.

Inherited From
PdfPageArea
Type
number

info

Gets or sets the document information, such as author name, document's creation date and so on.

Type
IPdfDocumentInfo

lineGap

Gets or sets the spacing between each line of text, in points.

The default value is 0.

Inherited From
PdfPageArea
Type
number

pageIndex

Gets or sets the index of the current page within the buffered pages range.

Use the bufferedPageRange method to get the range of buffered pages.

Type
number

pageSettings

Gets an object that represents the default page settings for the pages added automatically and for the addPage method.

Type
IPdfPageSettings

paths

Gets an object that provides ability to draw paths.

Inherited From
PdfPageArea
Type
PdfPaths

width

Gets the width of the area, in points.

Inherited From
PdfPageArea
Type
number

x

Gets or sets the X-coordinate (in points) of the current point in the text flow used to draw a text or an image.

Inherited From
PdfPageArea
Type
number

y

Gets or sets the Y-coordinate (in points) of the current point in the text flow used to draw a text or an image.

Inherited From
PdfPageArea
Type
number

Methods

addPage

addPage(settings?: IPdfPageSettings): PdfDocument

Adds a new page with the given settings.

If the settings parameter is omitted, then pageSettings will be used instead.

Parameters
Returns
PdfDocument

bufferedPageRange

bufferedPageRange(): IPdfBufferedPageRange

Gets the range of buffered pages.

Returns
IPdfBufferedPageRange

dispose

dispose(): void

Disposes the document.

Returns
void

drawImage

drawImage(url: string, x?: number, y?: number, options?: IPdfImageDrawSettings): PdfPageArea

Draws an image in JPG or PNG format with the given options.

If x and y are not defined, then @see:x and @see:y are used instead.

Finally, if the image was drawn in the text flow, the method updates @see:y. Hence, any subsequent text or image starts below this point.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

drawSvg

drawSvg(url: string, x?: number, y?: number, options?: IPdfSvgDrawSettings): PdfPageArea

Draws a SVG image with the given options.

If x and y are not defined, then @see:x and @see:y are used instead.

The method uses the values of the width and height attributes of the outermost svg element to determine the scale factor according to the options.width and options.height properties. If any of these attributes are omitted then scaling is not performed and the image will be rendered in its original size.

Finally, if the image was drawn in the text flow, the method updates @see:y. Hence, any subsequent text or image starts below this point. The increment value is defined by the options.height property or by the outermost svg element's height attribute, which comes first. If none of them is provided then @see:y will stay unchanged.

The method supports a limited set of SVG features and provided primarily for rendering wijmo 5 chart controls.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

drawText

drawText(text: string, x?: number, y?: number, options?: IPdfTextDrawSettings): IPdfTextMeasurementInfo

Draws a string with the given options and returns the measurement information.

If options.pen, options.brush or options.font are omitted, the current document's pen, brush or font are used (see setPen, setBrush, and setFont).

The string is drawn within the rectangular area for which top-left corner, width and height are defined by the x, y, options.width and options.height values. If x and y are not provided, the x and y properties are used instead.

The text is wrapped and clipped automatically within the area. If options.height is not provided and the text exceeds the bottom body edge, then a new page will be added to accommodate the text.

Finally, the method updates the value of the x and y properties. Hence, any subsequent text or image starts below this point (depending on the value of options.continued).

The measurement result doesn't reflect the fact that text can be split into multiple pages or columns; the text is treated as a single block.

Parameters
Inherited From
PdfPageArea
Returns
IPdfTextMeasurementInfo

end

end(): void

Finishes the document rendering.

Returns
void

lineHeight

lineHeight(font?: PdfFont): number

Gets the line height with a given font.

If font is not specified, then font used in the current document is used.

Parameters
Inherited From
PdfPageArea
Returns
number

measureText

measureText(text: string, font?: PdfFont, options?: IPdfTextSettings): IPdfTextMeasurementInfo

Measures a text with the given font and text drawing options without rendering it.

If font is not specified, then the font used in the current document is used.

The method uses the same text rendering engine as drawText, so it is tied up in the same way to @see:x and the right page margin, if options.width is not provided. The measurement result doesn't reflect the fact that text can be split into multiple pages or columns; the text is treated as a single block.

Parameters
Inherited From
PdfPageArea
Returns
IPdfTextMeasurementInfo

moveDown

moveDown(lines?: number, font?: PdfFont): PdfPageArea

Moves down the @see:y by a given number of lines using the given font or, using the font of current document, if not specified.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

moveUp

moveUp(lines?: number, font?: PdfFont): PdfPageArea

Moves up the @see:y by a given number of lines using the given font or, using the font of current document, if not specified.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

onEnded

onEnded(args: PdfDocumentEndedEventArgs): void

Raises the end event.

Parameters
Returns
void

onPageAdded

onPageAdded(args: EventArgs): void

Raises the pageAdded event.

Parameters
Returns
void

registerFont

registerFont(font: IPdfFontFile): PdfDocument

Registers a font from a source and associates it with a given font family name and font attributes.

Parameters
Returns
PdfDocument

registerFontAsync

registerFontAsync(font: IPdfFontFile, callback: Function): void

Registers a font from a URL asynchronously and associates it with a given font family name and font attributes.

The callback function takes a IPdfFontFile object as a parameter.

Parameters
Returns
void

restoreState

restoreState(): PdfDocument

Restores the state from the stack and applies it to the graphic context.

Returns
PdfDocument

rotate

rotate(angle: number, origin?: Point): PdfPageArea

Rotates the graphic context clockwise by a specified angle.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

saveState

saveState(): PdfDocument

Saves the state of the graphic context (including current pen, brush and transformation state) and pushes it onto stack.

Returns
PdfDocument

scale

scale(xFactor: number, yFactor?: number, origin?: Point): PdfPageArea

Scales the graphic context by a specified scaling factor.

The scaling factor value within the range [0, 1] indicates that the size will be decreased. The scaling factor value greater than 1 indicates that the size will be increased.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

setBrush

setBrush(brushOrColor: any): PdfDocument

Sets the default document brush. This brush will be used by the fill, fillAndStroke and drawText methods, if no specific brush is provided.

The brushOrColor argument can accept the following values:

  • A PdfBrush object.
  • A Color object or any string acceptable by the fromString method. In this case, the PdfBrush object with the specified color will be created internally.

Parameters
Returns
PdfDocument

setFont

setFont(font: PdfFont): PdfDocument

Sets the document font. If exact font with given style and weight properties is not found then,

  • It tries to search the closest font using font weight fallback.
  • If still nothing is found, it tries to find the closest font with other style in following order:
    • 'italic': 'oblique', 'normal'.
    • 'oblique': 'italic', 'normal'.
    • 'normal': 'oblique', 'italic'.

Parameters
Returns
PdfDocument

setPen

setPen(penOrColor: any): PdfDocument

Sets the default document pen. This pen will be used by the stroke, fillAndStroke and drawText methods, if no specific pen is provided.

The penOrColor argument can accept the following values:

  • A PdfPen object.
  • A Color object or any string acceptable by the fromString method. In this case, the PdfPen object with the specified color will be created internally.

Parameters
Returns
PdfDocument

transform

transform(a: number, b: number, c: number, d: number, e: number, f: number): PdfPageArea

Transforms the graphic context with given six numbers which represents a 3x3 transformation matrix.

A transformation matrix is written as follows:
ab0
cd0
ef1

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

translate

translate(x: number, y: number): PdfPageArea

Translates the graphic context with a given distance.

Parameters
Inherited From
PdfPageArea
Returns
PdfPageArea

Events

ended

Occurs when the document has been rendered.

Arguments
PdfDocumentEndedEventArgs

pageAdded

Occurs when a new page is added to the document.

Arguments
EventArgs