Skip to main content

Class: PdfEditableDocument

A mutable editor for applying incremental updates to an existing PDF document. It supports page edits, appended pages, form updates, structure changes, embedded resources, and incremental serialization.

Constructors​

Constructor​

new PdfEditableDocument(base): PdfEditableDocument;

Creates an editor around a parsed source PDF.

Parameters​

ParameterTypeDescription
baseParsedPdfDocumentThe parsed source PDF to edit.

Returns​

PdfEditableDocument

Methods​

addPage()​

addPage(options?): PdfPage;

Appends a new page and returns its page builder.

Parameters​

ParameterTypeDescription
optionsPageOptionsOptions that control the operation.

Returns​

PdfPage

The new page builder.


editPage()​

editPage(index): PdfPage;

Creates or returns a page builder for editing an existing page.

Parameters​

ParameterTypeDescription
indexnumberThe page index.

Returns​

PdfPage

The editable page builder.


embedTrueTypeFont()​

embedTrueTypeFont(data, options?): PdfEmbeddedFont;

Embeds a TrueType font for use by appended or edited pages.

Parameters​

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

Returns​

PdfEmbeddedFont

The result of the operation.


findEditableStructureElements()​

findEditableStructureElements(query?): readonly ParsedPdfEditableStructureElement[];

Finds editable tagged structure elements that match the supplied query.

Parameters​

ParameterTypeDescription
queryPdfEditableStructureQueryThe criteria used to match structure elements.

Returns​

readonly ParsedPdfEditableStructureElement[]

The result of the operation.


findSimilarStructureElements()​

findSimilarStructureElements(target, options?): readonly ParsedPdfEditableStructureElement[];

Finds tagged structure elements related to the supplied element.

Parameters​

ParameterTypeDescription
targetParsedPdfEditableStructureElementThe destination page, outline target, or structure element.
optionsPdfEditableStructureSimilarityOptionsOptions that control the operation.

Returns​

readonly ParsedPdfEditableStructureElement[]

The result of the operation.


flattenForms()​

flattenForms(): void;

Queues flattening for all parsed form fields.

Returns​

void


getPageCount()​

getPageCount(): number;

Returns the current page count including appended and inserted pages.

Returns​

number

The page count.


insertPage()​

insertPage(index, options?): PdfPage;

Inserts a new page at the requested position and returns its page builder.

Parameters​

ParameterTypeDescription
indexnumberThe page index.
optionsPageOptionsOptions that control the operation.

Returns​

PdfPage

The inserted page builder.


listEditableStructureElements()​

listEditableStructureElements(): readonly ParsedPdfEditableStructureElement[];

Returns editable tagged structure element handles from the source document.

Returns​

readonly ParsedPdfEditableStructureElement[]

The editable structure element handles.


movePage()​

movePage(fromIndex, toIndex): void;

Moves a page from one position to another.

Parameters​

ParameterTypeDescription
fromIndexnumberThe current page index.
toIndexnumberThe destination page index.

Returns​

void


removePage()​

removePage(index): void;

Removes a page from the editable page order.

Parameters​

ParameterTypeDescription
indexnumberThe page index.

Returns​

void


save()​

save(path): Promise<void>;

Serializes the incremental update and writes it to a file path. Convenience alias for writeToFile for Node.js callers.

Parameters​

ParameterTypeDescription
pathstringThe file path to write to.

Returns​

Promise<void>


setEncryption()​

setEncryption(options): void;

Sets encryption options for the next save, upgrading the encryption algorithm. New and modified objects will use the new encryption.

Parameters​

ParameterTypeDescription
optionsDocumentEncryptionOptionsEncryption options for the next save.

Returns​

void


setFieldValue()​

setFieldValue(name, value): void;

Queues a form field value update by field name.

/** Queues a form field value update by field name.

Parameters​

ParameterTypeDescription
namestringThe name to assign or look up.
valuestring | booleanThe value to write or apply.

Returns​

void


setStructureAltText()​

setStructureAltText(target, altText): void;

Queues alternate text updates for a tagged structure element.

Parameters​

ParameterTypeDescription
targetParsedPdfEditableStructureElementThe destination page, outline target, or structure element.
altTextstring | undefinedThe replacement alternate text, or undefined to clear it.

Returns​

void


setStructureReadingOrder()​

setStructureReadingOrder(orderedChildren): void;

Queues a child reading-order update for a tagged structure element.

Parameters​

ParameterTypeDescription
orderedChildrenreadonly ParsedPdfEditableStructureElement[]The child element handles in the desired reading order.

Returns​

void


setStructureRole()​

setStructureRole(target, role): void;

Queues a role update for a tagged structure element.

Parameters​

ParameterTypeDescription
targetParsedPdfEditableStructureElementThe destination page, outline target, or structure element.
role| string & object | PdfStandardStructureTagThe replacement structure role.

Returns​

void


setStructureRoles()​

setStructureRoles(targets, role): void;

Queues role updates for multiple tagged structure elements.

Parameters​

ParameterTypeDescription
targetsreadonly ParsedPdfEditableStructureElement[]The structure element handles to update.
role| string & object | PdfStandardStructureTagThe replacement structure role.

Returns​

void


setXmpMetadata()​

setXmpMetadata(metadata): void;

Queues an XMP metadata update or removal.

Parameters​

ParameterTypeDescription
metadataXmpMetadataInput | undefinedThe XMP metadata input, or undefined to clear it.

Returns​

void


sign()​

sign(options): void;

Adds a detached digital signature as an incremental update.

Parameters​

ParameterTypeDescription
optionsDocumentSignatureOptionsSignature options, including the CMS/PKCS#7 signer callback.

Returns​

void


toArrayBuffer()​

toArrayBuffer(): ArrayBuffer;

Serializes the incremental update into an ArrayBuffer.

Returns​

ArrayBuffer

The serialized PDF data as an ArrayBuffer.


toBlob()​

toBlob(): Blob;

Serializes the incremental update into a PDF Blob.

Returns​

Blob

The serialized PDF data as a Blob.


toIncrementalModel()​

toIncrementalModel(): PdfIncrementalUpdateModel;

Builds the internal incremental update model for serialization.

Returns​

PdfIncrementalUpdateModel

The internal incremental update model.


toUint8Array()​

toUint8Array(): Uint8Array;

Serializes the incremental update into PDF bytes.

Returns​

Uint8Array

The serialized or collected bytes.


updateInfo()​

updateInfo(info): void;

Queues updates to the document information dictionary.

Parameters​

ParameterTypeDescription
infoDocumentInfoThe document information metadata to merge.

Returns​

void


writePageContent()​

writePageContent(
index,
content,
mode): void;

Writes raw PDF content operators to an existing page's content stream.

Parameters​

ParameterTypeDescription
indexnumberThe page index.
contentstringRaw PDF content stream operators (e.g. "BT /F1 12 Tf (Hello) Tj ET").
mode"replace" | "append" | "prepend"How to apply the content: replace entirely, append after existing (wraps existing in q/Q), or prepend before existing (wraps existing in q/Q).

Returns​

void


writeTo()​

writeTo(sink): Promise<void>;

Streams the incremental update bytes to a byte sink.

Parameters​

ParameterTypeDescription
sinkByteSinkThe sink that receives written byte chunks.

Returns​

Promise<void>


writeToFile()​

writeToFile(path): Promise<void>;

Serializes the incremental update and writes it to a file path.

Parameters​

ParameterTypeDescription
pathstringThe file path to write to.

Returns​

Promise<void>


estimateSignatureSize()​

static estimateSignatureSize(certificateBytes?): number;

Estimates the byte size needed for a detached-signature placeholder.

Parameters​

ParameterTypeDescription
certificateBytes?Uint8Array<ArrayBufferLike> | nullOptional certificate bytes for size estimation.

Returns​

number

The estimated placeholder size in bytes.