sempdf

Class: PdfEditableDocument

sempdf v1.9.1


sempdf / PdfEditableDocument

Defined in: src/document.ts:7118

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;

Defined in: src/document.ts:7194

Creates an editor around a parsed source PDF.

Parameters

ParameterTypeDescription
baseParsedPdfDocumentThe parsed source PDF to edit.

Returns

PdfEditableDocument

Methods

addPage()

addPage(options?): PdfPage;

Defined in: src/document.ts:7237

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;

Defined in: src/document.ts:7347

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;

Defined in: src/document.ts:7430

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[];

Defined in: src/document.ts:7676

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[];

Defined in: src/document.ts:7723

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;

Defined in: src/document.ts:8172

Queues flattening for all parsed form fields.

Returns

void


getPageCount()

getPageCount(): number;

Defined in: src/document.ts:7276

Returns the current page count including appended and inserted pages.

Returns

number

The page count.


insertPage()

insertPage(index, options?): PdfPage;

Defined in: src/document.ts:7249

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[];

Defined in: src/document.ts:7661

Returns editable tagged structure element handles from the source document.

Returns

readonly ParsedPdfEditableStructureElement[]

The editable structure element handles.


movePage()

movePage(fromIndex, toIndex): void;

Defined in: src/document.ts:7310

Moves a page from one position to another.

Parameters

ParameterTypeDescription
fromIndexnumberThe current page index.
toIndexnumberThe destination page index.

Returns

void


removePage()

removePage(index): void;

Defined in: src/document.ts:7285

Removes a page from the editable page order.

Parameters

ParameterTypeDescription
indexnumberThe page index.

Returns

void


save()

save(path): Promise<void>;

Defined in: src/document.ts:8340

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;

Defined in: src/document.ts:7947

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;

Defined in: src/document.ts:7492

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;

Defined in: src/document.ts:7786

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;

Defined in: src/document.ts:7814

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;

Defined in: src/document.ts:7742

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;

Defined in: src/document.ts:7771

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;

Defined in: src/document.ts:7477

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;

Defined in: src/document.ts:7957

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;

Defined in: src/document.ts:8067

Serializes the incremental update into an ArrayBuffer.

Returns

ArrayBuffer

The serialized PDF data as an ArrayBuffer.


toArrayBufferAsync()

toArrayBufferAsync(): Promise<ArrayBuffer>;

Defined in: src/document.ts:8134

Async counterpart to toArrayBuffer.

Returns

Promise<ArrayBuffer>

The serialized PDF data as an ArrayBuffer.


toBlob()

toBlob(): Blob;

Defined in: src/document.ts:8103

Serializes the incremental update into a PDF Blob.

Returns

Blob

The serialized PDF data as a Blob.


toBlobAsync()

toBlobAsync(): Promise<Blob>;

Defined in: src/document.ts:8143

Async counterpart to toBlob.

Returns

Promise<Blob>

The serialized PDF data as a Blob.


toIncrementalModel()

toIncrementalModel(): PdfIncrementalUpdateModel;

Defined in: src/document.ts:8228

Builds the internal incremental update model for serialization.

Returns

PdfIncrementalUpdateModel

The internal incremental update model.


toUint8Array()

toUint8Array(): Uint8Array;

Defined in: src/document.ts:7967

Serializes the incremental update into PDF bytes.

Returns

Uint8Array

The serialized or collected bytes.


toUint8ArrayAsync()

toUint8ArrayAsync(): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: src/document.ts:8330

Async counterpart to toUint8Array.

Returns

Promise<Uint8Array<ArrayBufferLike>>

The serialized PDF data as a Uint8Array.


updateInfo()

updateInfo(info): void;

Defined in: src/document.ts:7453

Queues updates to the document information dictionary.

Parameters

ParameterTypeDescription
infoDocumentInfoThe document information metadata to merge.

Returns

void


writePageContent()

writePageContent(
   index, 
   content, 
   mode): void;

Defined in: src/document.ts:7386

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>;

Defined in: src/document.ts:8001

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>;

Defined in: src/document.ts:8321

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;

Defined in: src/document.ts:8312

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.

On this page