v5.20192.631
|

PdfDocument Class

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

Hierarchy

Constructors

constructor

Properties

bufferPages

bufferPages: boolean

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.

compress

compress: boolean

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.

currentPageSettings

currentPageSettings: IPdfPageSettings

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

returns

A IPdfPageSettings object that represents the current page settings.

document

document: PdfDocument

Gets the document object.

footer

Gets an object that represents a footer, the page area positioned right above the bottom margin.

header

Gets an object that represents a header, the page area positioned right below the top margin.

height

height: number

Gets the height of the area, in points.

info

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

lineGap

lineGap: number

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

The default value is 0.

pageIndex

pageIndex: number

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.

pageSettings

pageSettings: IPdfPageSettings

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

paths

paths: PdfPaths

Gets an object that provides ability to draw paths.

width

width: number

Gets the width of the area, in points.

x

x: number

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

y

y: number

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

Methods

addPage

bufferedPageRange

dispose

  • dispose(): void
  • Disposes the document.

    Returns void

drawImage

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

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

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

    Parameters

    • src: any

      A string containing the URL to get the image from or the data URI containing a base64 encoded image or a wijmo.pdf.IPdfImage object.

    • Optional x: number

      The x-coordinate of the point to draw the image at, in points.

    • Optional y: number

      The y-coordinate of the point to draw the image at, in points.

    • Optional options: IPdfImageDrawSettings

      Determines the image drawing options.

    Returns PdfPageArea

    The PdfPageArea object.

drawSvg

  • Draws a SVG image with the given options.

    If x and y are not defined, then x and 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 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 y will stay unchanged.

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

    Parameters

    • url: string

      A string containing the URL to get the SVG image from or the data URI containing a base64 encoded SVG image.

    • Optional x: number

      The x-coordinate of the point to draw the image at, in points.

    • Optional y: number

      The y-coordinate of the point to draw the image at, in points.

    • Optional options: IPdfSvgDrawSettings

      Determines the SVG image drawing options.

    Returns PdfPageArea

    The PdfPageArea object.

drawText

  • 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 PdfDocument.setPen, PdfDocument.setBrush, and PdfDocument.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 PdfDocument.x and PdfDocument.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 PdfDocument.x and PdfDocument.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

    • text: string

      The text to draw.

    • Optional x: number

      The X-coordinate of the point to draw the text at, in points.

    • Optional y: number

      The Y-coordinate of the point to draw the text at, in points.

    • Optional options: IPdfTextDrawSettings

      Determines the text drawing options.

    Returns IPdfTextMeasurementInfo

    A IPdfTextMeasurementInfo object determines the measurement information.

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

    • Optional font: PdfFont

      Font to get the line height.

    Returns number

    The line height, in points.

measureText

  • 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 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

    Returns IPdfTextMeasurementInfo

    A IPdfTextMeasurementInfo object determines the measurement information.

moveDown

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

    Parameters

    • Optional lines: number

      Number of lines to move down.

    • Optional font: PdfFont

      Font to calculate the line height.

    Returns PdfPageArea

    The PdfPageArea object.

moveUp

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

    Parameters

    • Optional lines: number

      Number of lines to move up.

    • Optional font: PdfFont

      Font to calculate the line height.

    Returns PdfPageArea

    The PdfPageArea object.

onEnded

onPageAdded

openImage

  • Opens an image in JPG or PNG format.

    Parameters

    • url: string

      A string containing the URL to get the image from or the data URI containing a base64 encoded image.

    Returns IPdfImage

    The IPdfImage object containing image data.

registerFont

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

    Parameters

    Returns PdfDocument

    The PdfDocument object.

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

    • font: IPdfFontFile

      The font to register.

    • callback: Function

      A callback function which will be called, when the font has been registered.

    Returns void

restoreState

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

    Returns PdfDocument

    The PdfDocument object.

rotate

  • Rotates the graphic context clockwise by a specified angle.

    Parameters

    • angle: number

      The rotation angle, in degrees.

    • Optional origin: Point

      The Point of rotation, in points. If it is not provided, then the top left corner is used.

    Returns PdfPageArea

saveState

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

    Returns PdfDocument

    The PdfDocument object.

scale

  • 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

    • xFactor: number

      The factor to scale the X dimension.

    • Optional yFactor: number

      The factor to scale the Y dimension. If it is not provided, it is assumed to be equal to xFactor.

    • Optional origin: Point

      The Point to scale around, in points. If it is not provided, then the top left corner is used.

    Returns PdfPageArea

    The PdfPageArea object.

setBrush

setFont

  • 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

    • font: PdfFont

      The font object to set.

    Returns PdfDocument

    The PdfDocument object.

setPen

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

    • a: number

      Value of the first row and first column.

    • b: number

      Value of the first row and second column.

    • c: number

      Value of the second row and first column.

    • d: number

      Value of the second row and second column.

    • e: number

      Value of the third row and first column.

    • f: number

      Value of the third row and second column.

    Returns PdfPageArea

    The PdfPageArea object.

translate

  • Translates the graphic context with a given distance.

    Parameters

    • x: number

      The distance to translate along the X-axis, in points.

    • y: number

      The distance to translate along the Y-axis, in points.

    Returns PdfPageArea

    The PdfPageArea object.

Events

ended

ended: Event

Occurs when the document has been rendered.

pageAdded

pageAdded: Event

Occurs when a new page is added to the document.