Skip to content

happypdf / PDFFont

Class: PDFFont

Defined in: src/api/PDFFont.ts:16

Represents a font that has been embedded in a [[PDFDocument]].

Implements

Properties

doc

ts
readonly doc: PDFDocument;

Defined in: src/api/PDFFont.ts:36

The document to which this font belongs.


name

ts
readonly name: string;

Defined in: src/api/PDFFont.ts:39

The name of this font.


ref

ts
readonly ref: PDFRef;

Defined in: src/api/PDFFont.ts:33

The unique reference assigned to this font within the document.

Methods

embed()

ts
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&lt;void&gt;

Resolves when the embedding is complete.

Implementation of

Embeddable.embed


encodeText()

ts
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

ParameterTypeDescription
textstringThe text to be encoded.

Returns

PDFHexString

The encoded text as a hex string.


getCharacterSet()

ts
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()

ts
glyphCountOfText(text): number;

Defined in: src/api/PDFFont.ts:91

Parameters

ParameterType
textstring

Returns

number


heightAtSize()

ts
heightAtSize(size, options?): number;

Defined in: src/api/PDFFont.ts:109

Measure the height of this font at a given size. For example:

js
const height = font.heightAtSize(24)

The options.descender value controls whether or not the font's descender is included in the height calculation.

Parameters

ParameterTypeDescription
sizenumberThe 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()

ts
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

ParameterTypeDescription
refPDFRefThe unique reference for this font.
docPDFDocumentThe document to which the font will belong.
embedderFontEmbedderThe embedder that will be used to embed the font.

Returns

PDFFont


sizeAtHeight()

ts
sizeAtHeight(height): number;

Defined in: src/api/PDFFont.ts:125

Compute the font size at which this font is a given height. For example:

js
const fontSize = font.sizeAtHeight(12)

Parameters

ParameterTypeDescription
heightnumberThe height to be used for this calculation.

Returns

number

The font size at which this font is the given height.


widthOfTextAtSize()

ts
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:

js
const width = font.widthOfTextAtSize('Foo Bar Qux Baz', 36)

Parameters

ParameterTypeDescription
textstringThe string of text to be measured.
sizenumberThe 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.

MIT Licensed. A fork of pdf-lib.