Skip to content

modern-pdf-lib


modern-pdf-lib / DrawTextOptions

Interface: DrawTextOptions

Defined in: src/core/pdfPage.ts:173

Options for PdfPage.drawText.

Properties

blendMode?

optional blendMode: BlendMode

Defined in: src/core/pdfPage.ts:199

Blend mode for compositing.


color?

optional color: Color

Defined in: src/core/pdfPage.ts:191

Text colour. Defaults to black.


font?

optional font: string | FontRef

Defined in: src/core/pdfPage.ts:187

Font to use for rendering.

Accepts either a FontRef object (returned by doc.embedFont()) or a font resource name string (e.g. 'F1').

When a FontRef is provided, its name property is used as the resource name and its CID encoder (if any) is used automatically.


lineHeight?

optional lineHeight: number

Defined in: src/core/pdfPage.ts:195

Line height for multi-line text.


maxWidth?

optional maxWidth: number

Defined in: src/core/pdfPage.ts:216

Maximum width in points before text is automatically wrapped.

When provided with a FontRef font (which has widthOfTextAtSize), the text is broken at word boundaries to fit within this width. If a single word exceeds maxWidth, it is broken at character level.

When the font is a plain string (no measurement available), this option is ignored.


opacity?

optional opacity: number

Defined in: src/core/pdfPage.ts:197

Opacity [0, 1].


renderingMode?

optional renderingMode: TextRenderingMode

Defined in: src/core/pdfPage.ts:201

Text rendering mode (fill, stroke, invisible, clip, etc.).


rotate?

optional rotate: Angle

Defined in: src/core/pdfPage.ts:193

Rotation angle.


size?

optional size: number

Defined in: src/core/pdfPage.ts:189

Font size in points.


wordBreaks?

optional wordBreaks: string[]

Defined in: src/core/pdfPage.ts:227

Characters at which text may be broken when wrapping.

Defaults to [' '] (space only). Pass additional characters such as [' ', '-', '/'] to allow breaks at hyphens, slashes, etc.

The break character is kept at the end of the preceding line (e.g. 'hello-' / 'world'), except for space which is consumed as in the default behaviour.


x?

optional x: number

Defined in: src/core/pdfPage.ts:175

X coordinate.


xSkew?

optional xSkew: Angle

Defined in: src/core/pdfPage.ts:203

Horizontal skew angle (italic-like effect).


y?

optional y: number

Defined in: src/core/pdfPage.ts:177

Y coordinate.


ySkew?

optional ySkew: Angle

Defined in: src/core/pdfPage.ts:205

Vertical skew angle.

Released under the MIT License.