Skip to content

modern-pdf-lib


modern-pdf-lib / PdfObjectRegistry

Class: PdfObjectRegistry

Defined in: src/core/pdfObjects.ts:471

Allocates monotonically increasing object numbers and stores the mapping from PdfRef → object value.

Constructors

Constructor

new PdfObjectRegistry(): PdfObjectRegistry

Returns

PdfObjectRegistry

Accessors

nextNumber

Get Signature

get nextNumber(): number

Defined in: src/core/pdfObjects.ts:542

The next object number that would be assigned.

Returns

number


size

Get Signature

get size(): number

Defined in: src/core/pdfObjects.ts:537

Total number of registered objects (≥ 1 in a valid PDF because of the free entry at object 0).

Returns

number

Methods

[iterator]()

[iterator](): IterableIterator<RegistryEntry>

Defined in: src/core/pdfObjects.ts:531

Iterate all entries in allocation order.

Returns

IterableIterator<RegistryEntry>


allocate()

allocate(): PdfRef

Defined in: src/core/pdfObjects.ts:507

Pre-allocate an object number and return the reference. Call assign later to attach the actual object.

Returns

PdfRef


assign()

assign(ref, object): void

Defined in: src/core/pdfObjects.ts:514

Assign an object to a previously allocated (or registered) reference.

Parameters

ref

PdfRef

object

PdfObject

Returns

void


filterReachable()

filterReachable(rootRefs): void

Defined in: src/core/pdfObjects.ts:555

Remove all registry entries that are not reachable from the given root references. This is used after rebuilding the document structure so that orphaned objects from the original (loaded) PDF don't bloat the output.

The walk follows every PdfRef found inside PdfDict, PdfArray, and PdfStream objects, handling cycles via a visited set.

Parameters

rootRefs

PdfRef[]

Returns

void


register()

register(object): PdfRef

Defined in: src/core/pdfObjects.ts:480

Register a new object, allocate an object number, and return its indirect reference.

Parameters

object

PdfObject

Returns

PdfRef


registerWithRef()

registerWithRef(ref, object): void

Defined in: src/core/pdfObjects.ts:493

Register a pre-built PdfRef with an object. Useful when the ref must be known before the object is fully built (e.g. the catalog references the page tree, and vice-versa).

Parameters

ref

PdfRef

object

PdfObject

Returns

void


resolve()

resolve(ref): PdfObject | undefined

Defined in: src/core/pdfObjects.ts:526

Look up the object for a given reference.

Parameters

ref

PdfRef

Returns

PdfObject | undefined

Released under the MIT License.