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

    Manages font embedding in PDF documents. Provides methods to embed TrueType and other font formats.

    Index

    Constructors

    Methods

    • Embeds a font from file data with automatic parsing and configuration. This is the recommended high-level API for embedding fonts.

      Parameters

      • fontData: ByteArray

        The font file bytes (TTF, OTF, or WOFF format)

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

        Optional configuration

        • OptionalfontName?: string

          Custom font name (defaults to PostScript name from font)

        • Optionalunicode?: boolean

          Use Unicode/Type0 encoding for non-ASCII characters

        • OptionalunicodeMappings?: Map<number, number>

          Custom CID to Unicode mappings for Type0 fonts

      Returns Promise<PdfFont>

      A PdfFont object representing the embedded font

      // Simple embedding with auto-generated name
      const font = await document.fonts.embedFromFile(fontData)
      field.font = font

      // With custom name and Unicode support
      const font = await document.fonts.embedFromFile(fontData, {
      fontName: 'MyCustomFont',
      unicode: true
      })
    • Embeds a standard PDF font (Type1). These fonts don't require font data as they're built into PDF viewers.

      Parameters

      • fontName:
            | "Helvetica"
            | "Helvetica-Bold"
            | "Helvetica-Oblique"
            | "Helvetica-BoldOblique"
            | "Times-Roman"
            | "Times-Bold"
            | "Times-Italic"
            | "Times-BoldItalic"
            | "Courier"
            | "Courier-Bold"
            | "Courier-Oblique"
            | "Courier-BoldOblique"
            | "Symbol"
            | "ZapfDingbats"

        One of the 14 standard PDF fonts

      Returns Promise<PdfFont>

      A PdfFont object representing the embedded font

    • Embeds a TrueType font with Unicode/Type0 support. Use this for fonts that need to display non-ASCII characters.

      Parameters

      • fontData: ByteArray

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

        Map of CID to Unicode code point for ToUnicode CMap

      Returns Promise<PdfFont>

      A PdfFont object representing the embedded font

    • Loads existing fonts from the PDF document. Traverses the page tree and extracts font information from page resources.

      Returns Promise<Map<string, PdfFont>>

      Map of font names to their PdfFont objects