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.
Example
Section titled “Example”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();Extends
Section titled “Extends”Handle<BaseGlue>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Builder(
options?):Builder
Parameters
Section titled “Parameters”options?
Section titled “options?”BuilderOptions = {}
version, file ID, producer, creation date, compression, tagging,
conformance profiles; text.
Returns
Section titled “Returns”Builder
Throws
Section titled “Throws”LaminaPdfError not-initialized, text-module-not-loaded; unknown-option.
Overrides
Section titled “Overrides”Handle<BaseGlue>.constructor
Accessors
Section titled “Accessors”hasText
Section titled “hasText”Get Signature
Section titled “Get Signature”get hasText():
boolean
Whether this builder draws in the text module (fonts and text).
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”[dispose]()
Section titled “[dispose]()”[dispose]():
void
Frees the handle at the end of a using block (an alias of free()).
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Handle.[dispose]
attach()
Section titled “attach()”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.
Parameters
Section titled “Parameters”string
the file name viewers show.
Uint8Array
the file’s contents.
string
its MIME type, such as text/xml.
options?
Section titled “options?”any
how the file relates to the document (relationship, default
unspecified), its description and modDate.
Returns
Section titled “Returns”this
Throws
Section titled “Throws”LaminaPdfError invalid-argument for a modDate that isn’t a PDF date,
unknown-option for an unknown key, builder-finished after Builder.finish.
destination()
Section titled “destination()”destination(
name,index,fit?):this
Defines the named destination name: page index, shown as fit (default: the page).
Parameters
Section titled “Parameters”string
number
any
Returns
Section titled “Returns”this
finish()
Section titled “finish()”finish():
Document
Writes fonts, links, the page tree, outline and metadata; the builder (and its unfinished pages) take no more calls afterwards.
Returns
Section titled “Returns”the new document (unsaved; its save is a full rewrite).
Throws
Section titled “Throws”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()
Section titled “font()”font(
font):FontInfo
Registers font with this builder (otherwise it is registered at first use).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Throws
Section titled “Throws”LaminaPdfError text-module-not-loaded, invalid-font, font-not-embeddable.
free()
Section titled “free()”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.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Handle.free
lang()
Section titled “lang()”lang(
tag):this
The natural language (/Lang), a BCP 47 tag.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
metadata()
Section titled “metadata()”metadata(
metadata):this
The metadata, written as the Info dictionary and an XMP packet.
Parameters
Section titled “Parameters”metadata
Section titled “metadata”MetadataInit
Returns
Section titled “Returns”this
outline()
Section titled “outline()”outline(
entries):string[]
Adds outline (bookmark) items with their children.
Parameters
Section titled “Parameters”entries
Section titled “entries”readonly OutlineEntryInit[]
Returns
Section titled “Returns”string[]
their IDs, in pre-order.
page()
Section titled “page()”page(
size?):Page
A new page of a named size or [width, height] in points.
Parameters
Section titled “Parameters”PageSizeName | readonly [number, number] = "A4"
Returns
Section titled “Returns”pageLabels()
Section titled “pageLabels()”pageLabels(
ranges):this
The page labels (i, ii, 1, 2…), ranges by first page; checked at finish.
Parameters
Section titled “Parameters”ranges
Section titled “ranges”readonly PageLabelInit[]
Returns
Section titled “Returns”this
viewerPreferences()
Section titled “viewerPreferences()”viewerPreferences(
preferences):this
How viewers present the document when it opens.
Parameters
Section titled “Parameters”preferences
Section titled “preferences”ViewerPreferencesInit
Returns
Section titled “Returns”this
create()
Section titled “create()”
staticcreate(options?):Builder
As new Builder(options).
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Builder