Skip to content

modern-pdf-lib


modern-pdf-lib / saveIncremental

Function: saveIncremental()

saveIncremental(originalBytes, registry, structure, changedObjects, options?): IncrementalSaveResult

Defined in: src/core/incrementalWriter.ts:245

Perform an incremental save of a PDF document.

Takes the original file bytes and a registry of objects (some new, some modified), and appends only the changed objects plus a new xref section and trailer.

The resulting bytes form a valid PDF file that preserves the original content byte-for-byte and appends the modifications.

Parameters

originalBytes

Uint8Array

The original PDF file bytes (unmodified).

registry

PdfObjectRegistry

The object registry containing all objects (original + new/modified).

structure

DocumentStructure

Document structure references (catalog, info, pages).

changedObjects

Set<number>

Set of object numbers that are new or modified.

options?

PdfSaveOptions

Optional save options (compression, etc.).

Returns

IncrementalSaveResult

The complete incremental save result.

Example

ts
const result = saveIncremental(originalBytes, registry, structure, changedObjects);
await writeFile('output.pdf', result.bytes);

Released under the MIT License.