Skip to content

PDFiumFont

@scaryterry/pdfium


Defined in: src/document/font.ts:43

Represents a font from a PDF text object.

The font holds a borrow on the parent page’s native resources, keeping them alive even after the page is disposed. Dispose the font (or use the using keyword) to release the borrow and allow the page to free its native memory.

for (const obj of page.objects()) {
if (obj instanceof PDFiumTextObject) {
using font = obj.getFont();
if (font) {
console.log('Font:', font.familyName, font.weight);
const metrics = font.getMetrics(12);
console.log('Ascent:', metrics.ascent);
}
}
}

get disposed(): boolean

Defined in: src/core/disposable.ts:73

Whether this resource has been disposed.

boolean

Disposable.disposed


get familyName(): string

Defined in: src/document/font.ts:79

Gets the family name of the font (e.g., ‘Helvetica’, ‘Times New Roman’).

string


get flags(): FontFlags

Defined in: src/document/font.ts:99

Gets the font descriptor flags.

FontFlags for the meaning of individual flags

FontFlags


get fontName(): string

Defined in: src/document/font.ts:89

Gets the base font name (PostScript name).

Returns an empty string if the font name is not available.

string


get isBold(): boolean

Defined in: src/document/font.ts:271

Checks if the font is bold (weight >= 700 or ForceBold flag set).

boolean


get isEmbedded(): boolean

Defined in: src/document/font.ts:137

Checks if the font is embedded in the document.

Embedded fonts include their glyph data in the PDF, ensuring consistent rendering across different systems.

boolean


get isFixedPitch(): boolean

Defined in: src/document/font.ts:250

Checks if the font is a fixed-pitch (monospace) font.

boolean


get isItalic(): boolean

Defined in: src/document/font.ts:264

Checks if the font is italic.

boolean


get isSerif(): boolean

Defined in: src/document/font.ts:257

Checks if the font is a serif font.

boolean


get italicAngle(): number

Defined in: src/document/font.ts:126

Gets the italic angle in degrees.

Returns a negative value for italic or oblique fonts, 0 for upright fonts.

number


get weight(): number

Defined in: src/document/font.ts:114

Gets the font weight (100-900).

Common values:

  • 400: Normal
  • 700: Bold

Returns 0 if the weight is not available.

number

[dispose](): void

Defined in: src/core/disposable.ts:148

Dispose of this resource, freeing WASM memory.

This method is idempotent - calling it multiple times has no effect after the first call.

void

Disposable.[dispose]


dispose(): void

Defined in: src/core/disposable.ts:164

Alias for Symbol.dispose for explicit calls.

void

document.dispose();

Disposable.dispose


getFontData(): Uint8Array<ArrayBufferLike> | undefined

Defined in: src/document/font.ts:219

Gets the raw font data if the font is embedded.

Uint8Array<ArrayBufferLike> | undefined

The font data as a Uint8Array, or undefined if not available


getGlyphWidth(glyphIndex, fontSize): number

Defined in: src/document/font.ts:202

Gets the width of a specific glyph.

ParameterTypeDescription
glyphIndexnumberThe glyph index (not character code)
fontSizenumberThe font size in points

number

The glyph width in points, or 0 if not available


getInfo(): FontInfo

Defined in: src/document/font.ts:149

Gets all font information in a single object.

More efficient than reading individual properties as it only validates disposal once.

FontInfo


getMetrics(fontSize): FontMetrics

Defined in: src/document/font.ts:175

Gets font metrics (ascent and descent) at a specific size.

ParameterTypeDescription
fontSizenumberThe font size in points

FontMetrics

Font metrics at the given size