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
| Parameter | Type | Description |
|---|---|---|
base | ParsedPdfDocument | The parsed source PDF to edit. |
Returns
PdfEditableDocument
Methods
addPage()
addPage(options?): PdfPage;
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;
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;
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[];
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[];
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;
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
| Parameter | Type | Description |
|---|---|---|
index | number | The page index. |
options | PageOptions | Options that control the operation. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
fromIndex | number | The current page index. |
toIndex | number | The destination page index. |
Returns
void
removePage()
removePage(index): void;
Removes a page from the editable page order.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | The 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
| Parameter | Type | Description |
|---|---|---|
path | string | The 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
| Parameter | Type | Description |
|---|---|---|
options | DocumentEncryptionOptions | Encryption 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
| 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;
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;
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;
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;
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;
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;
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;
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
| Parameter | Type | Description |
|---|---|---|
info | DocumentInfo | The document information metadata to merge. |
Returns
void