Skip to content

zeropdf v1.3.0


zeropdf / PdfPage

Class: PdfPage

Defined in: src/document.ts:3180

A mutable page builder for placing text, graphics, images, links, annotations, form fields, and structured content on a PDF page.

Constructors

Constructor

ts
new PdfPage(
   page, 
   embeddedFonts, 
   fontFamilies?, 
   textDefaults?, 
   origin?, 
   shapeDefaults?): PdfPage;

Defined in: src/document.ts:3189

Creates a page builder around an internal page model and embedded font registry.

Parameters

ParameterTypeDefault valueDescription
pageInternalPageModelundefinedThe internal page model to write into.
embeddedFontsReadonlyMap<string, ParsedTrueTypeFont>undefinedThe embedded font registry used for text layout.
fontFamiliesReadonlyMap<string, FontFamilyFaces>...Font families registered with the document, used to resolve a family name plus bold/italic flags to a concrete face.
textDefaults?TextDefaultsundefined-
origin?"bottom-left" | "top-left""bottom-left"-
shapeDefaults?ShapeStyleundefined-

Returns

PdfPage

Accessors

size

Get Signature

ts
get size(): CustomPageSize;

Defined in: src/document.ts:3250

Gets the page size.

Returns

CustomPageSize

The number of bytes.

Methods

bmp()

ts
bmp(data, options): this;

Defined in: src/document.ts:3652

Adds a BMP image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsBmpImageOptionsOptions that control the operation.

Returns

this


checkBox()

ts
checkBox(name, options): this;

Defined in: src/document.ts:3987

Adds a checkbox form field to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsCheckBoxOptionsOptions that control the operation.

Returns

this


choiceField()

ts
choiceField(name, options): this;

Defined in: src/document.ts:4015

Adds a choice form field to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsChoiceFieldOptionsOptions that control the operation.

Returns

this


circle()

ts
circle(
   cx, 
   cy, 
   radius, 
   style?): this;

Defined in: src/document.ts:3593

Draws a circle centered at (cx, cy).

Parameters

ParameterTypeDescription
cxnumberCenter x in PDF points.
cynumberCenter y in PDF points.
radiusnumberRadius in PDF points.
style?ShapeStyleFill/stroke styling. Stroked when omitted.

Returns

this


container()

Creates a tagged structure container on the page.

Param

The structure tag to create.

Param

Either structure options or a build callback.

Param

An optional build callback when options are provided separately.

Call Signature

ts
container(tag, build?): PdfStructureContainer;

Defined in: src/document.ts:3406

Creates a tagged structure container on the page.

Parameters
ParameterTypeDescription
tagPdfContainerTagThe structure tag to create.
build?(container) => voidAn optional callback that receives the created container.
Returns

PdfStructureContainer

The created structure container.

Call Signature

ts
container(
   tag, 
   options?, 
   build?): PdfStructureContainer;

Defined in: src/document.ts:3419

Creates a tagged structure container on the page.

Parameters
ParameterTypeDescription
tagPdfContainerTagThe structure tag to create.
options?PdfStructureOptionsOptions that control the operation.
build?(container) => voidAn optional callback that receives the created container.
Returns

PdfStructureContainer

The created structure container.


ellipse()

ts
ellipse(
   cx, 
   cy, 
   rx, 
   ry, 
   style?): this;

Defined in: src/document.ts:3607

Draws an ellipse centered at (cx, cy) with horizontal radius rx and vertical radius ry.

Parameters

ParameterTypeDescription
cxnumberCenter x in PDF points.
cynumberCenter y in PDF points.
rxnumberHorizontal radius in PDF points.
rynumberVertical radius in PDF points.
style?ShapeStyleFill/stroke styling. Stroked when omitted.

Returns

this


flow()

ts
flow(options?): PdfFlow;

Defined in: src/document.ts:3527

Creates a cursor-based flow helper for the page.

Parameters

ParameterTypeDescription
optionsFlowOptionsOptions that control the operation.

Returns

PdfFlow

The created flow helper.


freeText()

ts
freeText(options): this;

Defined in: src/document.ts:3893

Adds a free-text annotation to the page.

Parameters

ParameterTypeDescription
optionsFreeTextAnnotationOptionsOptions that control the operation.

Returns

this


gif()

ts
gif(data, options): this;

Defined in: src/document.ts:3707

Adds a GIF image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsGifImageOptionsOptions that control the operation.

Returns

this


highlight()

ts
highlight(options): this;

Defined in: src/document.ts:3768

Adds a highlight annotation to the page.

Parameters

ParameterTypeDescription
optionsHighlightAnnotationOptionsOptions that control the operation.

Returns

this


image()

ts
image(data, options): this;

Defined in: src/document.ts:3618

Adds a raster image, auto-detecting the format (PNG, JPEG, GIF, BMP, TIFF, WebP, JPEG 2000) from the data. For SVG use svg.

Parameters

ParameterTypeDescription
dataBinaryDataThe image bytes.
optionsJpegImageOptionsPlacement and tagging options.

Returns

this


jbig2()

ts
jbig2(data, options): this;

Defined in: src/document.ts:3663

Adds a JBIG2 image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsJbig2ImageOptionsOptions that control the operation.

Returns

this


jp2()

ts
jp2(data, options): this;

Defined in: src/document.ts:3685

Adds a JPEG 2000 image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsJp2ImageOptionsOptions that control the operation.

Returns

this


jpeg()

ts
jpeg(data, options): this;

Defined in: src/document.ts:3630

Adds a JPEG image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsJpegImageOptionsOptions that control the operation.

Returns

this


line()

ts
line(
   x1, 
   y1, 
   x2, 
   y2, 
   style?): this;

Defined in: src/document.ts:3578

Draws a straight line between two points.

Parameters

ParameterTypeDescription
x1numberStart x in PDF points.
y1numberStart y in PDF points.
x2numberEnd x in PDF points.
y2numberEnd y in PDF points.
style?ShapeStyleStroke styling.

Returns

this


ts
link(url, options): this;

Defined in: src/document.ts:3730

Adds a URI link annotation to the page.

Parameters

ParameterTypeDescription
urlstringThe URI target.
optionsUriLinkOptionsOptions that control the operation.

Returns

this


linkToPage()

ts
linkToPage(target, options): this;

Defined in: src/document.ts:3742

Adds an internal page link annotation.

Parameters

ParameterTypeDescription
targetPdfPageThe destination page, outline target, or structure element.
optionsPageLinkOptionsOptions that control the operation.

Returns

this


list()

ts
list(items, options): this;

Defined in: src/document.ts:3365

Adds a tagged list to the page.

Parameters

ParameterTypeDescription
itemsreadonly ListItem[]The list items to add.
optionsListOptionsOptions that control the operation.

Returns

this


note()

ts
note(options): this;

Defined in: src/document.ts:3868

Adds a text note annotation to the page.

Parameters

ParameterTypeDescription
optionsNoteAnnotationOptionsOptions that control the operation.

Returns

this


path()

ts
path(commands, style): this;

Defined in: src/document.ts:3545

Adds vector path commands to the page.

Parameters

ParameterTypeDescription
commandsPathCommand[]The vector path commands to add.
stylePathStyleThe drawing style for the path.

Returns

this


placeText()

ts
placeText(text, options): PlacedTextResult;

Defined in: src/document.ts:3336

Draws a single line of text and returns its measured size plus endY — the y where the next element can start. Unlike text (which chains), this returns layout feedback for manual stacking.

Parameters

ParameterTypeDescription
textstringThe text to draw.
optionsTextOptionsText options.

Returns

PlacedTextResult

{ width, height, endY } in PDF points.


placeTextBlock()

ts
placeTextBlock(text, options): PlacedTextBlockResult;

Defined in: src/document.ts:3352

Draws a wrapped text block and returns its measured size, line count, and endY — the y just below the block, for stacking the next element.

Parameters

ParameterTypeDescription
textstringThe text to wrap and draw.
optionsTextBlockOptionsText block options.

Returns

PlacedTextBlockResult

{ width, height, lineCount, endY } in PDF points.


png()

ts
png(data, options): this;

Defined in: src/document.ts:3641

Adds a PNG image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsPngImageOptionsOptions that control the operation.

Returns

this


pushButton()

ts
pushButton(name, options): this;

Defined in: src/document.ts:4074

Adds a push-button form field to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsPushButtonOptionsOptions that control the operation.

Returns

this


radioGroup()

ts
radioGroup(name, options): this;

Defined in: src/document.ts:4043

Adds a radio-button group to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsRadioGroupOptionsOptions that control the operation.

Returns

this


rect()

ts
rect(
   x, 
   y, 
   width, 
   height, 
   style?): this;

Defined in: src/document.ts:3565

Draws a rectangle. Convenience wrapper over path.

Parameters

ParameterTypeDescription
xnumberLeft edge in PDF points.
ynumberBottom edge in PDF points.
widthnumberWidth in PDF points.
heightnumberHeight in PDF points.
style?ShapeStyleFill/stroke styling. Stroked when omitted.

Returns

this


restoreState()

ts
restoreState(): this;

Defined in: src/document.ts:4136

Restores the most recently saved graphics state.

Returns

this


richText()

ts
richText(runs, options): this;

Defined in: src/document.ts:3304

Adds a paragraph of inline rich-text runs. Each InlineTextRun carries its own style yet the runs flow on the same line and wrap together as one paragraph. Runs that omit a style inherit it from options, then from the document defaults; runs carrying a link become clickable.

Supports left/center/right/justify alignment via options.align, line-level direction ("ltr"/"rtl"/"auto"), and writingMode: "vertical" (single column). In the flow and template layouts the paragraph wraps and splits across columns and pages.

Parameters

ParameterTypeDescription
runsreadonly InlineTextRun[]The styled inline runs to lay out together.
optionsRichTextOptionsBlock geometry and inherited style defaults.

Returns

this

Example

ts
page.richText(
  [
    { text: "Read the " },
    { text: "terms", bold: true, link: "https://x.com/terms" },
    { text: " before continuing." },
  ],
  { x: 56, y: 700, width: 300, fontSize: 12 },
);

rotate()

ts
rotate(degrees): this;

Defined in: src/document.ts:4176

Adds a rotation transform to subsequent page operations.

Parameters

ParameterTypeDescription
degreesnumberThe rotation angle in degrees.

Returns

this


saveState()

ts
saveState(): this;

Defined in: src/document.ts:4127

Saves the current graphics state.

Returns

this


scale()

ts
scale(x, y?): this;

Defined in: src/document.ts:4166

Adds a scale transform to subsequent page operations.

Parameters

ParameterTypeDefault valueDescription
xnumberundefinedThe horizontal transform value.
ynumberxThe vertical transform value.

Returns

this


setExtGState()

ts
setExtGState(options): this;

Defined in: src/document.ts:4208

Sets graphics-state parameters (alpha and/or blend mode) for subsequent painting operations. Emitted as an inline ExtGState entry referenced by the gs operator. Pair with saveState/restoreState to scope the effect.

Parameters

ParameterTypeDescription
optionsExtGStateOptionsAlpha and blend-mode options.

Returns

this


signatureField()

ts
signatureField(name, options): this;

Defined in: src/document.ts:4102

Adds a signature form field placeholder to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsSignatureFieldOptionsOptions that control the operation.

Returns

this


squiggly()

ts
squiggly(options): this;

Defined in: src/document.ts:3843

Adds a squiggly text-markup annotation to the page.

Parameters

ParameterTypeDescription
optionsSquigglyAnnotationOptionsOptions that control the operation.

Returns

this


strikeOut()

ts
strikeOut(options): this;

Defined in: src/document.ts:3818

Adds a strike-out text-markup annotation to the page.

Parameters

ParameterTypeDescription
optionsStrikeOutAnnotationOptionsOptions that control the operation.

Returns

this


structure()

Creates a tagged structure container on the page.

Param

The replacement structure role.

Param

Either structure options or a build callback.

Param

An optional build callback when options are provided separately.

Call Signature

ts
structure(role, build?): PdfStructureContainer;

Defined in: src/document.ts:3467

Creates a tagged structure container on the page.

Parameters
ParameterTypeDescription
role| string & object | PdfStandardStructureTagThe replacement structure role.
build?(container) => voidAn optional callback that receives the created container.
Returns

PdfStructureContainer

The created structure container.

Call Signature

ts
structure(
   role, 
   options?, 
   build?): PdfStructureContainer;

Defined in: src/document.ts:3480

Creates a tagged structure container on the page.

Parameters
ParameterTypeDescription
role| string & object | PdfStandardStructureTagThe replacement structure role.
options?PdfStructureOptionsOptions that control the operation.
build?(container) => voidAn optional callback that receives the created container.
Returns

PdfStructureContainer

The created structure container.


svg()

ts
svg(data, options): this;

Defined in: src/document.ts:3718

Adds an SVG graphic to the page.

Parameters

ParameterTypeDescription
datastring | BinaryDataThe SVG text data.
optionsSvgImageOptionsOptions that control the operation.

Returns

this


table()

ts
table(rows, options): this;

Defined in: src/document.ts:3385

Adds a tagged table to the page.

Parameters

ParameterTypeDescription
rowsreadonly TableRow[]The table rows to add.
optionsTableOptionsOptions that control the operation.

Returns

this


text()

ts
text(text, options): this;

Defined in: src/document.ts:3260

Adds text to the page.

Parameters

ParameterTypeDescription
textstringThe text to add.
optionsTextOptionsOptions that control the operation.

Returns

this


textBlock()

ts
textBlock(text, options): this;

Defined in: src/document.ts:3272

Adds a multiline text block to the page.

Parameters

ParameterTypeDescription
textstringThe text to add.
optionsTextBlockOptionsOptions that control the operation.

Returns

this


textField()

ts
textField(name, options): this;

Defined in: src/document.ts:3959

Adds a text form field to the page.

Parameters

ParameterTypeDescription
namestringThe name to assign or look up.
optionsTextFieldOptionsOptions that control the operation.

Returns

this


tiff()

ts
tiff(data, options): this;

Defined in: src/document.ts:3674

Adds a TIFF image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsTiffImageOptionsOptions that control the operation.

Returns

this


toInternalModel()

ts
toInternalModel(): InternalPageModel;

Defined in: src/document.ts:4219

Returns the internal page model used by serializers and editors.

Returns

InternalPageModel

The internal page model.


transform()

ts
transform(matrix): this;

Defined in: src/document.ts:4194

Adds a raw transformation matrix to subsequent page operations.

Parameters

ParameterTypeDescription
matrixTransformThe transformation matrix to apply.

Returns

this


translate()

ts
translate(x, y): this;

Defined in: src/document.ts:4155

Adds a translation transform to subsequent page operations.

Parameters

ParameterTypeDescription
xnumberThe horizontal transform value.
ynumberThe vertical transform value.

Returns

this


underline()

ts
underline(options): this;

Defined in: src/document.ts:3793

Adds an underline text-markup annotation to the page.

Parameters

ParameterTypeDescription
optionsUnderlineAnnotationOptionsOptions that control the operation.

Returns

this


webp()

ts
webp(data, options): this;

Defined in: src/document.ts:3696

Adds a WebP image to the page.

Parameters

ParameterTypeDescription
dataBinaryDataThe binary image or font data.
optionsWebpImageOptionsOptions that control the operation.

Returns

this

Released under the ISC license.