Class: PdfFlow
sempdf / PdfFlow
Defined in: src/document.ts:2227
A cursor-based layout helper for writing report-style content. It manages vertical flow, spacing, page breaks, headings, paragraphs, links, images, and tables.
Constructors
Constructor
new PdfFlow(
page,
embeddedFonts,
state,
parent?,
overflowHandler?,
fontFamilies?,
textDefaults?): PdfFlow;Defined in: src/document.ts:2236
Creates a cursor-based flow writer for a page and optional parent structure node.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
page | InternalPageModel | undefined | The internal page model to write into. |
embeddedFonts | ReadonlyMap<string, ParsedTrueTypeFont> | undefined | The embedded font registry used for text layout. |
state | FlowState | undefined | The mutable flow state to use. |
parent | InternalStructureNode | undefined | undefined | The parent structure element whose child order should change. |
overflowHandler | (() => PdfFlow) | undefined | undefined | - |
fontFamilies | ReadonlyMap<string, FontFamilyFaces> | ... | - |
textDefaults? | TextDefaults | undefined | - |
Returns
PdfFlow
Accessors
columnCount
Get Signature
get columnCount(): number;Defined in: src/document.ts:2362
Gets the total number of flow columns.
Returns
number
The flow column count.
columnIndex
Get Signature
get columnIndex(): number;Defined in: src/document.ts:2353
Gets the zero-based active column index.
Returns
number
The current flow column index.
cursorY
Get Signature
get cursorY(): number;Defined in: src/document.ts:2311
Gets the current vertical cursor position.
Returns
number
The current cursor y-coordinate.
remainingHeight
Get Signature
get remainingHeight(): number;Defined in: src/document.ts:2320
Gets the remaining writable height above the bottom margin.
Returns
number
The remaining writable height.
Methods
advanceColumn()
advanceColumn(): boolean;Defined in: src/document.ts:2371
Advances the flow cursor to the top of the next column on the same page.
Returns
boolean
Whether a next column was available.
bmp()
bmp(data, options?): this;Defined in: src/document.ts:3171
Adds a BMP image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
checkBox()
checkBox(name, options): this;Defined in: src/document.ts:4185
Adds a checkbox form field at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowCheckBoxOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
choiceField()
choiceField(name, options): this;Defined in: src/document.ts:4229
Adds a choice form field at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowChoiceFieldOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
circle()
circle(
cx?,
cy?,
radius?,
style?): this;Defined in: src/document.ts:4620
Adds a circle path at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
cx? | number | Center x-coordinate override. |
cy? | number | Center y-coordinate override. |
radius? | number | Radius override. |
style? | PathStyle | The drawing style for the circle. |
Returns
this
This flow helper for chaining.
code()
code(
source,
options?,
language?): this;Defined in: src/document.ts:2778
Adds a preformatted code block at the current flow cursor: monospaced text with leading whitespace and hard line breaks preserved, drawn on a background band.
Long lines soft-wrap (continuation lines keep the wrapped line's
indentation) unless wrap: false clips them. The block splits across pages
and columns line-by-line, repeating the background band and padding on each
fragment, so a block longer than a page is fine.
Parameters
| Parameter | Type | Description |
|---|---|---|
source | string | The code to render. Tabs expand to tabSize spaces. |
options | FlowCodeOptions | Typography, background, gutter, and highlighting options. |
language? | string | Optional language name recorded as the structure element's expansion text. |
Returns
this
This flow helper for chaining.
ellipse()
ellipse(
cx?,
cy?,
rx?,
ry?,
style?): this;Defined in: src/document.ts:4663
Adds an ellipse at the current flow cursor. Like circle but with
independent horizontal (rx) and vertical (ry) radii; advances the
cursor by the full height (2 × ry).
Parameters
| Parameter | Type | Description |
|---|---|---|
cx? | number | Center x override (defaults to the column center). |
cy? | number | Center y override (defaults to one ry below the cursor). |
rx? | number | Horizontal radius override. |
ry? | number | Vertical radius override. |
style? | PathStyle | The drawing style for the ellipse. |
Returns
this
This flow helper for chaining.
estimate()
estimate(block): number;Defined in: src/document.ts:2472
Estimates the height a template block would consume.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | TemplateBlock | The template block to estimate. |
Returns
number
The estimated height.
estimateTableRowHeights()
estimateTableRowHeights(rows, options?): readonly number[];Defined in: src/document.ts:3629
Returns the rendered height of each row in a table at the current flow position.
Heights include cell padding and the trailing rowGap. Use this to pre-plan
row-by-row page splits when rendering large tables.
Parameters
| Parameter | Type | Description |
|---|---|---|
rows | readonly TableRow[] | The table rows to measure. |
options | FlowTableOptions | Options that control the operation. |
Returns
readonly number[]
Per-row heights including padding and trailing rowGap.
freeText()
freeText(options): this;Defined in: src/document.ts:4519
Adds a free-text annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowFreeTextOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
gif()
gif(data, options?): this;Defined in: src/document.ts:3231
Adds a GIF image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
heading()
heading(
text,
options?,
annotations?): this;Defined in: src/document.ts:2405
Adds a heading at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | readonly InlineTextRun[] | The text to add. |
options | FlowHeadingOptions | Options that control the operation. |
annotations? | readonly ParagraphTextAnnotation[] | - |
Returns
this
This flow helper for chaining.
highlight()
highlight(options): this;Defined in: src/document.ts:4400
Adds a highlight annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowHighlightOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
html()
html(html, options?): this;Defined in: src/document.ts:2758
Converts an HTML fragment to blocks and renders them at the current flow cursor. A convenience wrapper over htmlToBlocks + render.
For document-level rendering prefer an html template block (or
htmlToBlocks() spread into your block list): those are expanded before
pagination, so headings inside the HTML still feed the TOC and auto-outline.
Parameters
| Parameter | Type | Description |
|---|---|---|
html | string | The HTML to convert. Tag soup is tolerated. |
options | HtmlToBlocksOptions | Conversion and styling options. |
Returns
this
This flow helper for chaining.
jbig2()
jbig2(data, options?): this;Defined in: src/document.ts:3183
Adds a JBIG2 image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
jp2()
jp2(data, options?): this;Defined in: src/document.ts:3207
Adds a JPEG 2000 image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
jpeg()
jpeg(data, options?): this;Defined in: src/document.ts:3159
Adds a JPEG image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
line()
line(
x1,
y1,
x2,
y2,
style?): this;Defined in: src/document.ts:4696
Draws a straight line between two absolute points. Unlike rect and circle, a line does not consume vertical flow space.
Parameters
| Parameter | Type | Description |
|---|---|---|
x1 | number | Start x in PDF points. |
y1 | number | Start y in PDF points. |
x2 | number | End x in PDF points. |
y2 | number | End y in PDF points. |
style? | PathStyle | The drawing style for the line. |
Returns
this
This flow helper for chaining.
link()
link(
text,
url,
options?): this;Defined in: src/document.ts:3257
Adds a text link at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text to add. |
url | string | The URI target. |
options | FlowLinkOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
list()
list(items, options): this;Defined in: src/document.ts:4713
Adds a tagged list at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
items | readonly ListItem[] | The list items to add. |
options | FlowListOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
moveDown()
moveDown(distance?): this;Defined in: src/document.ts:3457
Moves the flow cursor downward by the supplied distance.
Parameters
| Parameter | Type | Description |
|---|---|---|
distance | number | The distance to move the cursor. |
Returns
this
This flow helper for chaining.
note()
note(options): this;Defined in: src/document.ts:4477
Adds a text note annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowNoteOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
paragraph()
paragraph(
text,
options?,
annotations?): this;Defined in: src/document.ts:2580
Adds a paragraph at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text to add. |
options | FlowTextOptions | Options that control the operation. |
annotations? | readonly ParagraphTextAnnotation[] | - |
Returns
this
This flow helper for chaining.
path()
path(
commands,
style,
height): this;Defined in: src/document.ts:4562
Adds vector path commands at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
commands | PathCommand[] | The vector path commands to add. |
style | PathStyle | The drawing style for the path. |
height | number | The vertical extent consumed by the path. |
Returns
this
This flow helper for chaining.
png()
png(data, options?): this;Defined in: src/document.ts:3147
Adds a PNG image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
pushButton()
pushButton(name, options): this;Defined in: src/document.ts:4313
Adds a push-button form field at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowPushButtonOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
radioGroup()
radioGroup(name, options): this;Defined in: src/document.ts:4273
Adds a radio-button group at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowRadioGroupOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
rect()
rect(
x?,
y?,
width?,
height?,
style?): this;Defined in: src/document.ts:4585
Adds a rectangle path at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
x? | number | Horizontal position override. |
y? | number | Vertical position override (bottom edge). |
width? | number | Width override. |
height? | number | Height override. |
style? | PathStyle | The drawing style for the rectangle. |
Returns
this
This flow helper for chaining.
render()
render(blocks, stylesheet?): this;Defined in: src/document.ts:2460
Renders a sequence of template blocks into the flow.
Parameters
| Parameter | Type | Description |
|---|---|---|
blocks | readonly TemplateBlock[] | The template blocks to render. |
stylesheet? | TemplateStylesheet | Optional named styles merged beneath each block's inline options. |
Returns
this
This flow helper for chaining.
resolveTableColumnWidths()
resolveTableColumnWidths(rows, options?): readonly number[] | undefined;Defined in: src/document.ts:3419
Resolves a table's effective column widths exactly as table would
lay them out. Used by the template paginator so a table split across pages
sizes its columns identically on every slice (a "auto" table is measured
once over all rows, not re-measured per slice). Returns numeric widths, or
undefined when the table uses the default equal-width columns.
Parameters
| Parameter | Type |
|---|---|
rows | readonly TableRow[] |
options | FlowTableOptions |
Returns
readonly number[] | undefined
richParagraph()
richParagraph(
runs,
options?,
annotations?): this;Defined in: src/document.ts:2619
Parameters
| Parameter | Type |
|---|---|
runs | readonly InlineTextRun[] |
options | FlowRichTextOptions |
annotations? | readonly ParagraphTextAnnotation[] |
Returns
this
section()
section(
blocks,
role?,
structure?,
stylesheet?): this;Defined in: src/document.ts:4110
Renders a section of template blocks within an optional structure container.
Parameters
| Parameter | Type | Description |
|---|---|---|
blocks | readonly TemplateBlock[] | Child blocks to render. |
role? | PdfContainerTag | Optional structure role (e.g. "Sect", "Div"). |
structure? | PdfStructureOptions | Optional structure options. |
stylesheet? | TemplateStylesheet | - |
Returns
this
This flow helper for chaining.
signatureField()
signatureField(name, options): this;Defined in: src/document.ts:4357
Adds a signature form field placeholder at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowSignatureFieldOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
squiggly()
squiggly(options): this;Defined in: src/document.ts:4433
Adds a squiggly text-markup annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowHighlightOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
strikeOut()
strikeOut(options): this;Defined in: src/document.ts:4422
Adds a strike-out text-markup annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowHighlightOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
svg()
svg(data, options?): this;Defined in: src/document.ts:3243
Adds an SVG graphic at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | BinaryData | The SVG text data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
table()
table(rows, options?): this;Defined in: src/document.ts:3365
Adds a table at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
rows | readonly TableRow[] | The table rows to add. |
options | FlowTableOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
textBlock()
textBlock(
text,
options?,
annotations?): this;Defined in: src/document.ts:3118
Adds a text block at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text to add. |
options | FlowTextOptions | Options that control the operation. |
annotations? | readonly ParagraphTextAnnotation[] | Optional inline annotations anchored to substrings of the rendered text. |
Returns
this
This flow helper for chaining.
textField()
textField(name, options): this;Defined in: src/document.ts:4141
Adds a text form field at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The fully-qualified field name. |
options | FlowTextFieldOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
tiff()
tiff(data, options?): this;Defined in: src/document.ts:3195
Adds a TIFF image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
underline()
underline(options): this;Defined in: src/document.ts:4411
Adds an underline text-markup annotation at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FlowHighlightOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.
webp()
webp(data, options?): this;Defined in: src/document.ts:3219
Adds a WebP image at the current flow cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | FlowImageOptions | Options that control the operation. |
Returns
this
This flow helper for chaining.