happypdf / PDFFont
Class: PDFFont
Defined in: src/api/PDFFont.ts:16
Represents a font that has been embedded in a [[PDFDocument]].
Implements
Properties
doc
readonly doc: PDFDocument;Defined in: src/api/PDFFont.ts:36
The document to which this font belongs.
name
readonly name: string;Defined in: src/api/PDFFont.ts:39
The name of this font.
ref
readonly ref: PDFRef;Defined in: src/api/PDFFont.ts:33
The unique reference assigned to this font within the document.
Methods
embed()
embed(): Promise<void>;Defined in: src/api/PDFFont.ts:151
> NOTE: You probably don't need to call this method directly. The > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will > automatically ensure all fonts get embedded.
Embed this font in its document.
Returns
Promise<void>
Resolves when the embedding is complete.
Implementation of
encodeText()
encodeText(text): PDFHexString;Defined in: src/api/PDFFont.ts:69
> NOTE: You probably don't need to call this method directly. The > [[PDFPage.drawText]] method will automatically encode the text it is > given.
Encodes a string of text in this font.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text to be encoded. |
Returns
The encoded text as a hex string.
getCharacterSet()
getCharacterSet(): number[];Defined in: src/api/PDFFont.ts:134
Get the set of unicode code points that can be represented by this font.
Returns
number[]
The set of unicode code points supported by this font.
glyphCountOfText()
glyphCountOfText(text): number;Defined in: src/api/PDFFont.ts:91
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
number
heightAtSize()
heightAtSize(size, options?): number;Defined in: src/api/PDFFont.ts:109
Measure the height of this font at a given size. For example:
const height = font.heightAtSize(24)The options.descender value controls whether or not the font's descender is included in the height calculation.
Parameters
| Parameter | Type | Description |
|---|---|---|
size | number | The font size to be used for this measurement. |
options? | { descender?: boolean; } | The options to be used when computing this measurement. |
options.descender? | boolean | - |
Returns
number
The height of this font at the given size.
of()
static of(
ref,
doc,
embedder): PDFFont;Defined in: src/api/PDFFont.ts:29
> NOTE: You probably don't want to call this method directly. Instead, > consider using the [[PDFDocument.embedFont]] and > [[PDFDocument.embedStandardFont]] methods, which will create instances > of [[PDFFont]] for you.
Create an instance of [[PDFFont]] from an existing ref and embedder
Parameters
| Parameter | Type | Description |
|---|---|---|
ref | PDFRef | The unique reference for this font. |
doc | PDFDocument | The document to which the font will belong. |
embedder | FontEmbedder | The embedder that will be used to embed the font. |
Returns
PDFFont
sizeAtHeight()
sizeAtHeight(height): number;Defined in: src/api/PDFFont.ts:125
Compute the font size at which this font is a given height. For example:
const fontSize = font.sizeAtHeight(12)Parameters
| Parameter | Type | Description |
|---|---|---|
height | number | The height to be used for this calculation. |
Returns
number
The font size at which this font is the given height.
widthOfTextAtSize()
widthOfTextAtSize(text, size): number;Defined in: src/api/PDFFont.ts:85
Measure the width of a string of text drawn in this font at a given size. For example:
const width = font.widthOfTextAtSize('Foo Bar Qux Baz', 36)Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The string of text to be measured. |
size | number | The font size to be used for this measurement. |
Returns
number
The width of the string of text when drawn in this font at the given size.