Skip to content

PDFiumPageBuilder

@scaryterry/pdfium


Defined in: src/document/builder.ts:232

Builder for adding content to a PDF page.

Obtained from PDFiumDocumentBuilder.addPage. Use method chaining to add shapes, text, and other page objects.

Content is generated automatically when the document is saved — there is no need to call generateContent() on builder pages.

using builder = pdfium.createDocument();
const page = builder.addPage({ width: 595, height: 842 });
const font = builder.loadStandardFont('Helvetica');
page
.addRectangle(50, 700, 200, 100, { fill: { r: 200, g: 220, b: 255, a: 255 } })
.addText('Hello, PDF!', 60, 750, font, 24);
const bytes = builder.save();

get disposed(): boolean

Defined in: src/core/disposable.ts:74

Whether this resource has been disposed.

boolean

Disposable.disposed

[dispose](): void

Defined in: src/core/disposable.ts:163

Dispose of this resource, freeing WASM memory.

This method is idempotent - calling it multiple times has no effect after the first call.

void

Disposable.[dispose]


addEllipse(cx, cy, rx, ry, style?): this

Defined in: src/document/builder.ts:353

Add an ellipse (or circle) to the page, inscribed in the given bounding box.

Approximated with four cubic Bezier segments (standard technique).

ParameterTypeDescription
cxnumberCentre X in points
cynumberCentre Y in points
rxnumberHorizontal radius in points
rynumberVertical radius in points
style?ShapeStyleFill and stroke style

this

this for method chaining


addLine(x1, y1, x2, y2, style?): this

Defined in: src/document/builder.ts:327

Add a straight line to the page.

ParameterTypeDescription
x1numberStart X in points
y1numberStart Y in points
x2numberEnd X in points
y2numberEnd Y in points
style?ShapeStyleStroke style (fill is ignored for lines)

this

this for method chaining


addRectangle(x, y, w, h, style?): this

Defined in: src/document/builder.ts:257

Add a rectangle to the page.

ParameterTypeDescription
xnumberLeft position in points
ynumberBottom position in points
wnumberWidth in points
hnumberHeight in points
style?ShapeStyleFill and stroke style options

this

this for method chaining


addText(text, x, y, font, fontSize, colour?): this

Defined in: src/document/builder.ts:287

Add a text object to the page.

ParameterTypeDescription
textstringThe text content
xnumberX position in points
ynumberY position in points
fontPDFiumBuilderFontFont from builder.loadStandardFont()
fontSizenumberFont size in points
colour?ColourOptional text colour (defaults to black)

this

this for method chaining


dispose(): void

Defined in: src/core/disposable.ts:179

Alias for Symbol.dispose for explicit calls.

void

document.dispose();

Disposable.dispose