Skip to content

Builder

Builds a new document: pages, navigation and metadata; Builder.finish returns a Document to save. Created in the text module when it is loaded (or text: true), else in the reading module (text, extract, then base; vector and image pages only).

await init({ text: true });
const b = new Builder({ producer: "my app" });
const page = b.page("A4");
page.surface().text("Hello, world!", { font: Font.standard("Helvetica"), size: 24, at: [72, 96] });
page.finish();
const bytes = b.finish().save();

new Builder(options?): Builder

BuilderOptions = {}

version, file ID, producer, creation date, compression; text.

Builder

LaminaError not-initialized, text-module-not-loaded; unknown-option.

get hasText(): boolean

Whether this builder draws in the text module (fonts and text).

boolean

[dispose](): void

Frees the builder at the end of a using block.

void


destination(name, index, fit?): this

Defines the named destination name: page index, shown as fit (default: the page).

string

number

any

this


finish(): Document

Writes fonts, links, the page tree, outline and metadata; the builder (and its unfinished pages) take no more calls afterwards.

Document

the new document (unsaved; its save is a full rewrite).

LaminaError page-index-out-of-range, unknown-destination, invalid-page-labels, invalid-geometry, subset-failed, builder-finished.


font(font): FontInfo

Registers font with this builder (otherwise it is registered at first use).

Font

FontInfo

LaminaError text-module-not-loaded, invalid-font, font-not-embeddable.


free(): void

Frees the builder’s WASM memory now (finish does this itself); the builder takes no more calls afterwards. Unfinished pages are freed with Page.free.

void


lang(tag): this

The natural language (/Lang), a BCP 47 tag.

string

this


metadata(metadata): this

The metadata, written as the Info dictionary and an XMP packet.

MetadataInit

this


outline(entries): string[]

Adds outline (bookmark) items with their children.

readonly OutlineEntryInit[]

string[]

their IDs, in pre-order.


page(size?): Page

A new page of a named size or [width, height] in points.

PageSizeName | readonly [number, number] = "A4"

Page


pageLabels(ranges): this

The page labels (i, ii, 1, 2…), ranges by first page; checked at finish.

readonly PageLabelInit[]

this


viewerPreferences(preferences): this

How viewers present the document when it opens.

ViewerPreferencesInit

this


static create(options?): Builder

As new Builder(options).

BuilderOptions

Builder