PDFiumFont
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.
Example
Section titled “Example”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); } }}Extends
Section titled “Extends”Accessors
Section titled “Accessors”disposed
Section titled “disposed”Get Signature
Section titled “Get Signature”get disposed():
boolean
Defined in: src/core/disposable.ts:73
Whether this resource has been disposed.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”familyName
Section titled “familyName”Get Signature
Section titled “Get Signature”get familyName():
string
Defined in: src/document/font.ts:79
Gets the family name of the font (e.g., ‘Helvetica’, ‘Times New Roman’).
Returns
Section titled “Returns”string
Get Signature
Section titled “Get Signature”get flags():
FontFlags
Defined in: src/document/font.ts:99
Gets the font descriptor flags.
FontFlags for the meaning of individual flags
Returns
Section titled “Returns”fontName
Section titled “fontName”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”string
isBold
Section titled “isBold”Get Signature
Section titled “Get Signature”get isBold():
boolean
Defined in: src/document/font.ts:271
Checks if the font is bold (weight >= 700 or ForceBold flag set).
Returns
Section titled “Returns”boolean
isEmbedded
Section titled “isEmbedded”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”boolean
isFixedPitch
Section titled “isFixedPitch”Get Signature
Section titled “Get Signature”get isFixedPitch():
boolean
Defined in: src/document/font.ts:250
Checks if the font is a fixed-pitch (monospace) font.
Returns
Section titled “Returns”boolean
isItalic
Section titled “isItalic”Get Signature
Section titled “Get Signature”get isItalic():
boolean
Defined in: src/document/font.ts:264
Checks if the font is italic.
Returns
Section titled “Returns”boolean
isSerif
Section titled “isSerif”Get Signature
Section titled “Get Signature”get isSerif():
boolean
Defined in: src/document/font.ts:257
Checks if the font is a serif font.
Returns
Section titled “Returns”boolean
italicAngle
Section titled “italicAngle”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”number
weight
Section titled “weight”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”[dispose]()
Section titled “[dispose]()”[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.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”dispose()
Section titled “dispose()”dispose():
void
Defined in: src/core/disposable.ts:164
Alias for Symbol.dispose for explicit calls.
Returns
Section titled “Returns”void
Example
Section titled “Example”document.dispose();Inherited from
Section titled “Inherited from”getFontData()
Section titled “getFontData()”getFontData():
Uint8Array<ArrayBufferLike> |undefined
Defined in: src/document/font.ts:219
Gets the raw font data if the font is embedded.
Returns
Section titled “Returns”Uint8Array<ArrayBufferLike> | undefined
The font data as a Uint8Array, or undefined if not available
getGlyphWidth()
Section titled “getGlyphWidth()”getGlyphWidth(
glyphIndex,fontSize):number
Defined in: src/document/font.ts:202
Gets the width of a specific glyph.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
glyphIndex | number | The glyph index (not character code) |
fontSize | number | The font size in points |
Returns
Section titled “Returns”number
The glyph width in points, or 0 if not available
getInfo()
Section titled “getInfo()”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.
Returns
Section titled “Returns”getMetrics()
Section titled “getMetrics()”getMetrics(
fontSize):FontMetrics
Defined in: src/document/font.ts:175
Gets font metrics (ascent and descent) at a specific size.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fontSize | number | The font size in points |
Returns
Section titled “Returns”Font metrics at the given size