Appearance
zeropdf / PdfEditableDocument
Class: PdfEditableDocument
Defined in: src/document.ts:5389
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
ts
new PdfEditableDocument(base): PdfEditableDocument;Defined in: src/document.ts:5465
Creates an editor around a parsed source PDF.
Parameters
| Parameter | Type | Description |
|---|---|---|
base | ParsedPdfDocument | The parsed source PDF to edit. |
Returns
PdfEditableDocument
Methods
addPage()
ts
addPage(options?): PdfPage;Defined in: src/document.ts:5508
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()
ts
editPage(index): PdfPage;Defined in: src/document.ts:5618
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()
ts
embedTrueTypeFont(data, options?): PdfEmbeddedFont;Defined in: src/document.ts:5701
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()
ts
findEditableStructureElements(query?): readonly ParsedPdfEditableStructureElement[];Defined in: src/document.ts:5947
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()
ts
findSimilarStructureElements(target, options?): readonly ParsedPdfEditableStructureElement[];Defined in: src/document.ts:5994
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()
ts
flattenForms(): void;Defined in: src/document.ts:6391
Queues flattening for all parsed form fields.
Returns
void
getPageCount()
ts
getPageCount(): number;Defined in: src/document.ts:5547
Returns the current page count including appended and inserted pages.
Returns
number
The page count.
insertPage()
ts
insertPage(index, options?): PdfPage;Defined in: src/document.ts:5520
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()
ts
listEditableStructureElements(): readonly ParsedPdfEditableStructureElement[];Defined in: src/document.ts:5932
Returns editable tagged structure element handles from the source document.
Returns
readonly ParsedPdfEditableStructureElement[]
The editable structure element handles.
movePage()
ts
movePage(fromIndex, toIndex): void;Defined in: src/document.ts:5581
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()
ts
removePage(index): void;Defined in: src/document.ts:5556
Removes a page from the editable page order.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | The page index. |
Returns
void
save()
ts
save(path): Promise<void>;Defined in: src/document.ts:6552
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()
ts
setEncryption(options): void;Defined in: src/document.ts:6218
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()
ts
setFieldValue(name, value): void;Defined in: src/document.ts:5763
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()
ts
setStructureAltText(target, altText): void;Defined in: src/document.ts:6057
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()
ts
setStructureReadingOrder(orderedChildren): void;Defined in: src/document.ts:6085
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()
ts
setStructureRole(target, role): void;Defined in: src/document.ts:6013
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()
ts
setStructureRoles(targets, role): void;Defined in: src/document.ts:6042
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()
ts
setXmpMetadata(metadata): void;Defined in: src/document.ts:5748
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()
ts
sign(options): void;Defined in: src/document.ts:6228
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()
ts
toArrayBuffer(): ArrayBuffer;Defined in: src/document.ts:6324
Serializes the incremental update into an ArrayBuffer.
Returns
ArrayBuffer
The serialized PDF data as an ArrayBuffer.
toBlob()
ts
toBlob(): Blob;Defined in: src/document.ts:6350
Serializes the incremental update into a PDF Blob.
Returns
Blob
The serialized PDF data as a Blob.
toIncrementalModel()
ts
toIncrementalModel(): PdfIncrementalUpdateModel;Defined in: src/document.ts:6447
Builds the internal incremental update model for serialization.
Returns
PdfIncrementalUpdateModel
The internal incremental update model.
toUint8Array()
ts
toUint8Array(): Uint8Array;Defined in: src/document.ts:6238
Serializes the incremental update into PDF bytes.
Returns
Uint8Array
The serialized or collected bytes.
updateInfo()
ts
updateInfo(info): void;Defined in: src/document.ts:5724
Queues updates to the document information dictionary.
Parameters
| Parameter | Type | Description |
|---|---|---|
info | DocumentInfo | The document information metadata to merge. |
Returns
void
writePageContent()
ts
writePageContent(
index,
content,
mode): void;Defined in: src/document.ts:5657
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()
ts
writeTo(sink): Promise<void>;Defined in: src/document.ts:6259
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()
ts
writeToFile(path): Promise<void>;Defined in: src/document.ts:6540
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()
ts
static estimateSignatureSize(certificateBytes?): number;Defined in: src/document.ts:6531
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.