Class: PdfEditableDocument
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
| Parameter | Type | Description |
|---|---|---|
base | ParsedPdfDocument | The 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
| Parameter | Type | Description |
|---|---|---|
options | PageOptions | Options that control the operation. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
index | number | The page index. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
data | BinaryData | The binary image or font data. |
options | EmbedTrueTypeFontOptions | Options that control the operation. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
query | PdfEditableStructureQuery | The 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
| Parameter | Type | Description |
|---|---|---|
target | ParsedPdfEditableStructureElement | The destination page, outline target, or structure element. |
options | PdfEditableStructureSimilarityOptions | Options 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
| Parameter | Type | Description |
|---|---|---|
index | number | The page index. |
options | PageOptions | Options that control the operation. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
fromIndex | number | The current page index. |
toIndex | number | The destination page index. |
Returns
void
removePage()
removePage(index): void;Defined in: src/document.ts:7285
Removes a page from the editable page order.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The 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
| Parameter | Type | Description |
|---|---|---|
options | DocumentEncryptionOptions | Encryption 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
| Parameter | Type | Description |
|---|---|---|
name | string | The name to assign or look up. |
value | string | boolean | The 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
| Parameter | Type | Description |
|---|---|---|
target | ParsedPdfEditableStructureElement | The destination page, outline target, or structure element. |
altText | string | undefined | The 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
| Parameter | Type | Description |
|---|---|---|
orderedChildren | readonly 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
| Parameter | Type | Description |
|---|---|---|
target | ParsedPdfEditableStructureElement | The destination page, outline target, or structure element. |
role | | string & object | PdfStandardStructureTag | The 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
| Parameter | Type | Description |
|---|---|---|
targets | readonly ParsedPdfEditableStructureElement[] | The structure element handles to update. |
role | | string & object | PdfStandardStructureTag | The replacement structure role. |
Returns
void
setXmpMetadata()
setXmpMetadata(metadata): void;Defined in: src/document.ts:7477
Queues an XMP metadata update or removal.
Parameters
| Parameter | Type | Description |
|---|---|---|
metadata | XmpMetadataInput | undefined | The 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
| Parameter | Type | Description |
|---|---|---|
options | DocumentSignatureOptions | Signature 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
| Parameter | Type | Description |
|---|---|---|
info | DocumentInfo | The 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
| Parameter | Type | Description |
|---|---|---|
index | number | The page index. |
content | string | Raw 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
| Parameter | Type | Description |
|---|---|---|
sink | ByteSink | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The 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
| Parameter | Type | Description |
|---|---|---|
certificateBytes? | Uint8Array<ArrayBufferLike> | null | Optional certificate bytes for size estimation. |
Returns
number
The estimated placeholder size in bytes.