Skip to content

a11ydocs v1.7.0


a11ydocs / PdfPage

Class: PdfPage

Defined in: src/document.ts:3353

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:3362

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:3423

Gets the page size.

Returns

CustomPageSize

The number of bytes.

Methods

bmp()

ts
bmp(data, options): this;

Defined in: src/document.ts:3890

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:4225

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:4253

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:3831

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:3585

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:3598

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:3845

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:3706

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:4131

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:3945

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:4006

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:3856

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:3901

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:3923

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:3868

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:3816

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:3968

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:3980

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:3538

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:4106

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:3783

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:3509

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:3525

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:3879

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:4312

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:4281

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:3803

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:4374

Restores the most recently saved graphics state.

Returns

this


richText()

ts
richText(runs, options): this;

Defined in: src/document.ts:3477

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:4414

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:4365

Saves the current graphics state.

Returns

this


scale()

ts
scale(x, y?): this;

Defined in: src/document.ts:4404

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:4446

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:4340

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:4081

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:4056

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:3646

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:3659

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:3956

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:3558

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:3433

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:3445

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:4197

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:3912

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:4457

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:4432

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:4393

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:4031

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:3934

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.