Skip to content
Lamina PDF
Unreleased

These docs describe changes that aren’t released yet. For the newest release, see the released docs.

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). finish() frees its WebAssembly memory; to drop it unfinished, use using or Builder.free.

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();
  • Handle<BaseGlue>

new Builder(options?): Builder

BuilderOptions = {}

version, file ID, producer, creation date, compression, tagging, conformance profiles; text.

Builder

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

Handle<BaseGlue>.constructor

get hasText(): boolean

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

boolean

[dispose](): void

Frees the handle at the end of a using block (an alias of free()).

void

Handle.[dispose]


attach(name, bytes, mime, options?): this

Attaches a file: PDF/A-3b’s associated files, such as an e-invoice’s XML. The same name again replaces the file. PDF/A-2b and PDF/A-2u refuse attachments at Builder.finish, and every PDF/A profile refuses one without a MIME type there.

string

the file name viewers show.

Uint8Array

the file’s contents.

string

its MIME type, such as text/xml.

any

how the file relates to the document (relationship, default unspecified), its description and modDate.

this

LaminaPdfError invalid-argument for a modDate that isn’t a PDF date, unknown-option for an unknown key, builder-finished after Builder.finish.


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).

LaminaPdfError page-index-out-of-range, unknown-destination, invalid-page-labels, invalid-geometry, subset-failed, builder-finished; under a profile (profiles in the options), the first rule the document breaks, with that rule’s code (the error reference lists them, from profile-version-conflict on).


font(font): FontInfo

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

Font

FontInfo

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


free(): void

Frees the handle’s memory now; without it, the garbage collector frees it later. A second call does nothing, and any other call afterwards throws disposed. Prefer using, which calls this at the end of the block.

void

Handle.free


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