phpdftk API Documentation

IncrementalWriter
in package

FinalYes

Incremental update writer — ISO 32000-2 §7.5.6.

Appends modified/new objects to an existing PDF without rewriting the original file content. The result is a valid PDF where the original bytes are preserved intact, followed by:

  1. New/modified indirect objects
  2. A new cross-reference section (covering only the changed objects)
  3. A new trailer with /Prev pointing to the original xref offset
  4. startxref + %%EOF

This preserves existing digital signatures and is significantly more efficient than a full rewrite for small modifications (e.g., form filling, annotation additions).

Table of Contents

Methods

__construct()  : mixed
addModifiedObject()  : void
Add a modified object (preserving its original object number).
addNewObject()  : PdfReference
Add a new object (assigns a new sequential object number).
deleteObject()  : void
Mark an object as deleted (free) in the incremental update.
fromReader()  : self
Create an IncrementalWriter from a PdfReader instance.
generate()  : string
Generate the incremental update and return the complete PDF (original bytes + appended update).
getPdfVersion()  : PdfVersion
getVersionWarnings()  : array<int, string>
save()  : void
Write the incrementally updated PDF to a file.
setDeprecationHandler()  : void
setEncryption()  : void
Configure encryption for new/modified objects in the incremental update.
setStrictDeprecation()  : void
setStrictVersionMode()  : void
wasVersionBumped()  : bool
Whether the version was auto-bumped during object registration.

Methods

__construct()

public __construct(string $originalPdf, int $originalSize, int $originalXrefOffset, PdfReference $rootRef[, PdfReference|null $infoRef = null ][, PdfArray|null $idArray = null ][, PdfReference|null $encryptRef = null ][, bool $compressStreams = true ][, bool $useXRefStream = false ][, PdfVersion $version = PdfVersion::V1_7 ]) : mixed
Parameters
$originalPdf : string

The complete bytes of the original PDF

$originalSize : int

Total object count from the original trailer /Size

$originalXrefOffset : int

The startxref byte offset from the original PDF

$rootRef : PdfReference

The /Root reference from the original trailer

$infoRef : PdfReference|null = null

The /Info reference (if present)

$idArray : PdfArray|null = null

The /ID array from the original trailer

$encryptRef : PdfReference|null = null

The /Encrypt reference (if present)

$compressStreams : bool = true
$useXRefStream : bool = false
$version : PdfVersion = PdfVersion::V1_7

addModifiedObject()

Add a modified object (preserving its original object number).

public addModifiedObject(PdfObject $object) : void

The object must already have its objectNumber set to the original value from the PDF being updated.

Parameters
$object : PdfObject

deleteObject()

Mark an object as deleted (free) in the incremental update.

public deleteObject(int $objNum) : void

The object will appear as a free entry in the new xref section.

Parameters
$objNum : int

fromReader()

Create an IncrementalWriter from a PdfReader instance.

public static fromReader(PdfReader $reader, string $originalPdf[, bool $compressStreams = true ][, bool $useXRefStream = false ]) : self

Extracts the necessary metadata (size, xref offset, root, info, ID, encrypt) from the reader's trailer.

Parameters
$reader : PdfReader
$originalPdf : string
$compressStreams : bool = true
$useXRefStream : bool = false
Return values
self

generate()

Generate the incremental update and return the complete PDF (original bytes + appended update).

public generate() : string
Return values
string

getVersionWarnings()

public getVersionWarnings() : array<int, string>
Return values
array<int, string>

save()

Write the incrementally updated PDF to a file.

public save(string $path) : void
Parameters
$path : string

setDeprecationHandler()

public setDeprecationHandler(Closure $handler) : void
Parameters
$handler : Closure

setEncryption()

Configure encryption for new/modified objects in the incremental update.

public setEncryption(PdfEncryptor $encryptor) : void

The encryptor must use the same key as the original PDF's encryption. New and modified objects will be encrypted before serialization.

Parameters
$encryptor : PdfEncryptor

setStrictDeprecation()

public setStrictDeprecation([bool $strict = true ]) : void
Parameters
$strict : bool = true

setStrictVersionMode()

public setStrictVersionMode([bool $strict = true ]) : void
Parameters
$strict : bool = true

wasVersionBumped()

Whether the version was auto-bumped during object registration.

public wasVersionBumped() : bool

When true, callers that have access to the Catalog should update its /Version entry via an incremental update, since the original PDF header bytes are immutable.

Return values
bool

        
On this page

Search results