PDFFont
Represents a font that has been embedded in a [[PDFDocument]].
Class PDFFont
class PDFFont implements defaultRepresents a font that has been embedded in a [[PDFDocument]].
Properties
doc
PDFDocumentThe document to which this font belongs.
name
stringThe name of this font.
ref
PDFRefThe unique reference assigned to this font within the document.
of
(ref: PDFRef, doc: PDFDocument, embedder: FontEmbedder) => PDFFontNOTE: 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
Methods
embed
embed(): Promise<void>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): PDFHexStringNOTE: 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
text: stringThe text to be encoded.
Returns PDFHexString
The encoded text as a hex string.
getCharacterSet
getCharacterSet(): number[]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?: { descender?: boolean }): numberMeasure 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
size: numberThe font size to be used for this measurement.options?: { descender?: boolean }The options to be used when computing this measurement.
Returns number
The height of this font at the given size.
sizeAtHeight
sizeAtHeight(height: number): numberCompute the font size at which this font is a given height. For example:
const fontSize = font.sizeAtHeight(12)Parameters
height: numberThe 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): numberMeasure 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
text: stringThe string of text to be measured.size: numberThe 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.