pdf-lite - v1.6.0
    Preparing search index...

    Represents an embedded font in a PDF document. Extends PdfIndirectObject with a PdfDictionary content for the font dict.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    cachedTokens?: PdfToken[]

    Cached byte representation of the object, if available

    compressed?: boolean
    content: PdfFontDictionary
    encryptable?: boolean
    generationNumber: number
    immutable: boolean = false

    Indicates whether the object is immutable (cannot be modified)

    modified: boolean = true

    Indicates whether the object has been modified. By default, assume it has been modified because it's a new object

    objectNumber: number
    offset: Ref<number>
    orderIndex?: number
    postTokens?: PdfToken[]

    Optional tokens to prepend or append during serialization

    preTokens?: PdfToken[]

    Optional tokens to prepend or append during serialization

    resourceName: string

    The PDF resource name used in content streams (e.g., 'F1', 'F2'). This is the identifier used in PDF operators like /F1 12 Tf.

    COURIER: PdfFont = ...
    COURIER_BOLD: PdfFont = ...
    COURIER_BOLD_OBLIQUE: PdfFont = ...
    COURIER_OBLIQUE: PdfFont = ...
    HELVETICA: PdfFont = ...
    HELVETICA_BOLD: PdfFont = ...
    HELVETICA_BOLD_OBLIQUE: PdfFont = ...
    HELVETICA_OBLIQUE: PdfFont = ...
    MAX_ORDER_INDEX: 2147483647
    SYMBOL: PdfFont = ...
    TIMES_BOLD: PdfFont = ...
    TIMES_BOLD_ITALIC: PdfFont = ...
    TIMES_ITALIC: PdfFont = ...
    TIMES_ROMAN: PdfFont = ...
    ZAPF_DINGBATS: PdfFont = ...

    Accessors

    • get encodingMap(): Map<number, string> | null

      Gets the encoding map from the font's Encoding dictionary's Differences array. Maps byte codes to Unicode characters for custom-encoded fonts.

      Returns Map<number, string> | null

    • get fontType(): "Type1" | "TrueType" | "Type0" | "MMType1" | "Type3" | undefined

      Gets the font type (Subtype in PDF).

      Returns "Type1" | "TrueType" | "Type0" | "MMType1" | "Type3" | undefined

    • set fontType(
          type: "Type1" | "TrueType" | "Type0" | "MMType1" | "Type3" | undefined,
      ): void

      Sets the font type (Subtype in PDF).

      Parameters

      • type: "Type1" | "TrueType" | "Type0" | "MMType1" | "Type3" | undefined

      Returns void

    • get isTrailingDelimited(): boolean

      Returns true if this object's serialized form ends with a self-delimiting character (e.g., ), >, ], >>). Such objects do not require trailing whitespace before the next token.

      Returns boolean

    • get reverseEncodingMap(): Map<string, number> | undefined

      Gets the reverse encoding map (Unicode character → byte code). Useful for encoding text back into the font's custom encoding.

      Returns Map<string, number> | undefined

    Methods

    • Gets the character width scaled to the specified font size. Returns null if the character is not in the font's width table.

      Parameters

      • charCode: number

        The character code to get the width for

      • fontSize: number

        The font size to scale to

      Returns number | null

      The scaled character width or null if not found

    • Gets character widths for all characters in a string. Returns null for characters not in the font's width table.

      Parameters

      • text: string

        The text to get character widths for

      • fontSize: number

        The font size to scale to

      Returns (number | null)[]

      Array of character widths (null for missing characters)

    • Gets the raw character width (in 1000-unit em square) for a character code. Returns null if the character is not in the font's width table.

      Parameters

      • charCode: number

        The character code to get the width for

      Returns number | null

      The raw character width or null if not found

    • Checks if the font has width data for a character code.

      Parameters

      • charCode: number

        The character code to check

      Returns boolean

      True if width data is available, false otherwise

    • Parameters

      • fontData: ByteArray
      • Optionaloptions: { fontName?: string; unicode?: boolean; unicodeMappings?: Map<number, number> }

      Returns PdfFont

    • Creates a PdfFont from a FontParser instance. Extracts all necessary information from the parser including font name, descriptor, and font data.

      Parameters

      • parser: FontParser

        A FontParser instance (TtfParser, OtfParser, or WoffParser)

      Returns PdfFont

      A PdfFont instance ready to be written to the PDF

    • Creates a standard PDF Type1 font (one of the 14 built-in fonts). These fonts don't require font data as they're built into PDF viewers.

      Parameters

      • fontName: PdfStandardFontName

        One of the 14 standard PDF fonts

      • Optionalwidths: number[]

        Optional AFM widths array (1/1000 em units) for chars 32–126

      Returns PdfFont

      A PdfFont instance ready to be written to the PDF

    • Creates a Type0 (composite) font with Unicode support. Use this for fonts that need to display non-ASCII characters.

      Parameters

      • fontData: ByteArray

        The TrueType font file bytes

      • fontName: string

        The name to use for this font in the PDF

      • descriptor: UnicodeFontDescriptor

        Unicode font descriptor with CID metrics

      • OptionalunicodeMappings: Map<number, number>

        Optional map of CID to Unicode code point for ToUnicode CMap

      Returns PdfFont

      A PdfFont instance ready to be written to the PDF