PDFFont
Represents a font that has been embedded in a PDFDocument.
Hierarchy
- PDFFont
Implements
Index
Properties
Methods
Properties
doc
• doc: PDFDocument
Defined in api/PDFFont.ts:36
The document to which this font belongs.
name
• name: string
Defined in api/PDFFont.ts:39
The name of this font.
ref
• ref: PDFRef
Defined in api/PDFFont.ts:33
The unique reference assigned to this font within the document.
Methods
embed
▸ embed(): Promise‹void›
Defined in api/PDFFont.ts:147
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.
encodeText
▸ encodeText(text
: string): PDFHexString
Defined in 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:
Name | Type | Description |
---|---|---|
text | string | The text to be encoded. |
Returns: PDFHexString
The encoded text as a hex string.
getCharacterSet
▸ getCharacterSet(): number[]
Defined in api/PDFFont.ts:130
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.
heightAtSize
▸ heightAtSize(size
: number, options?
: undefined | object): number
Defined in api/PDFFont.ts:105
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:
Name | Type | Description |
---|---|---|
size | number | The font size to be used for this measurement. |
options? | undefined | object | The options to be used when computing this measurement. |
Returns: number
The height of this font at the given size.
sizeAtHeight
▸ sizeAtHeight(height
: number): number
Defined in api/PDFFont.ts:121
Compute the font size at which this font is a given height. For example:
const fontSize = font.sizeAtHeight(12)
Parameters:
Name | 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
: string, size
: number): number
Defined in api/PDFFont.ts:86
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:
Name | 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.
Static
of
▸ of(ref
: PDFRef, doc
: PDFDocument, embedder
: FontEmbedder): PDFFont‹›
Defined in 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:
Name | 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‹›