[]
        
(Showing Draft Content)

PdfDocument Class

PdfDocument Class

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

Heirarchy

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 IPdfDocumentOptions object passed to the PdfDocument constructor. 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 IPdfDocumentOptions object passed to the PdfDocument constructor.

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.

displayTitle

displayTitle: boolean

Gets a value that specifies whether the window's title bar should display the document title taken from IPdfDocumentInfo.title. If false, the name of the PDF file should be displayed.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

The default value is false.

document

document: PdfDocument

Gets the document object.

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

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.

lang

lang: string

Gets a value that represents the default natural language of the document.

The language code is a 2-character ISO 639 language code (e.g. "en" for English or "ja" for Japanese) followed by an optional 2-character ISO 3166 country code (e.g. "US" for the United States or "JP" for Japan). For example: "en", "en-US", "ja-JP".

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

The default value is undefined which means that the document does not have the default natural language.

lineGap

lineGap: number

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

The default value is 0.

ownerPassword

ownerPassword: string

Gets the PDF owner password.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

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.

permissions

permissions: IPdfPermissions

Gets an object that represents PDF file permissions.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor. Changing the property after creating PdfDocument will not have any effect.

tagged

tagged: boolean

Gets a value that indicates that the document conforms to Tagged PDF conventions. For a document to be recognized as a Tagged PDF document this value must be true.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

Note: tagged PDF requires document version 1.4 or higher.

The default value is false.

userPassword

userPassword: string

Gets the PDF user password.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

version

version: PdfVersion

Gets PDF file version.

This property can be assigned using the IPdfDocumentOptions object passed to the PdfDocument constructor.

The default version is PdfVersion.v1_3.

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

addTag

  • Adds the tag element to the document’s structure tree.

    Parameters

    • tag: IPdfTag

      Theelement to add to the document’s structure tree.

    Returns PdfDocument

    The PdfDocument object.

artifact

beginArtifact

beginTagContent

  • Begins marking the content with the given tag and returns the tag content element, an object which represent a reference to the marked content. The tag content element can be incorporated into the document's structure tree by adding to a tag element. Each call of beginTagContent() should be enclosed with endTagContent.

    For example:

    let content = doc.beginTagContent(wijmo.pdf.PdfTagType.P);
    doc.drawText('Hello, world!');
    doc.endTagContent();
    
    let tag = doc.tag(wijmo.pdf.PdfTagType.P);
    tag.add(content);
    doc.addTag(tag);
    

    Note: Marking tag content will automatically end current marking of tag content (and any descendent marking).

    Parameters

    Returns IPdfTagContent

    The IPdfTagContent object that repesents a reference to the marked content.

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: string | IPdfImage

      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 returned by the openImage method.

    • 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

endArtifact

endTagContent

  • Ends the tag content marking.

    For example:

    let content = doc.beginTagContent(wijmo.pdf.PdfTagType.P);
    doc.drawText('Hello, world!');
    doc.endTagContent();
    

    Returns PdfPageArea

    The PdfPageArea object.

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: Object): 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: Object

      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

tag

  • Creates a tag element that represents an item in the document's structure tree.

    For example:

    // Mark some text as a paragraph.
      let content = doc.beginTagContent(wijmo.pdf.PdfTagType.P);
    doc.drawText('Hello, world!');
      doc.endTagContent();
    
      // Create the tag element and add content to it.
      let tag = doc.tag(wijmo.pdf.PdfTagType.P);
      tag.add(content);
    
      // Add the tag element to the document's structure tree.
      doc.addTag(tag);
    

    The same, using a callback function:

    doc.addTag(doc.tag(wijmo.pdf.PdfTagType.P, () =>  doc.drawText('Hello, world! ')));
    

    Parameters

    • type: PdfTagType

      The type of a tag element.

    • Optional child: PdfTagOrContent | PdfTagOrContent[]

      An optional child element or array of child elements.

    • Optional options: IPdfTagOptions

      An optional IPdfTagOptions object used to configure the element.

      The following child types are supported:

      • A IPdfTag object to nest within the element.
      • A IPdfTagContent object, a reference to the marked content to associate with the element.
      • A callback function that will be automatically executed when the created element is attached to the document's structure tree. The content created by this function will be marked with the tag specified by the **type** parameter and associated with the element.

    Returns IPdfTag

    The IPdfTag tag element.

tagContent

  • Marks content with the given tag and returns the tag content element, an object which represent a reference to the marked content. The tag content element can be incorporated into the document's structure tree by adding to a tag element.

    For example:

    let content = doc.tagContent(wijmo.pdf.PdfTagType.P, () => doc.drawText('Hello, world!'));
    
    let tag = doc.tag(wijmo.pdf.PdfTagType.P);
    tag.add(content);
    doc.addTag(tag);
    

    Parameters

    Returns IPdfTagContent

    The IPdfTagContent object that repesents a reference to the marked content.

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

Occurs when the document has been rendered.

pageAdded

Occurs when a new page is added to the document.