Skip to content

modern-pdf-lib


modern-pdf-lib / PdfLayerManager

Class: PdfLayerManager

Defined in: src/layers/optionalContent.ts:121

Manages a collection of optional content groups (layers) for a PDF document.

Provides methods to add, remove, and query layers, and to serialize the /OCProperties dictionary that goes into the catalog.

Constructors

Constructor

new PdfLayerManager(): PdfLayerManager

Returns

PdfLayerManager

Methods

addLayer()

addLayer(name, visible?): PdfLayer

Defined in: src/layers/optionalContent.ts:131

Add a new layer.

Parameters

name

string

The display name for the layer.

visible?

boolean = true

Whether the layer is visible by default.

Returns

PdfLayer

The newly created layer.


getLayer()

getLayer(name): PdfLayer | undefined

Defined in: src/layers/optionalContent.ts:143

Get a layer by name.

Parameters

name

string

The layer name.

Returns

PdfLayer | undefined

The layer, or undefined if not found.


getLayers()

getLayers(): PdfLayer[]

Defined in: src/layers/optionalContent.ts:152

Get all layers.

Returns

PdfLayer[]

A copy of the layers array.


removeLayer()

removeLayer(name): void

Defined in: src/layers/optionalContent.ts:161

Remove a layer by name.

Parameters

name

string

The layer name.

Returns

void


toOCProperties()

toOCProperties(registry): PdfDict

Defined in: src/layers/optionalContent.ts:174

Build the /OCProperties dictionary for the document catalog.

This dictionary describes all optional content groups and their default configurations.

Parameters

registry

PdfObjectRegistry

The PDF object registry.

Returns

PdfDict

The /OCProperties dictionary (not indirect).


fromDict()

static fromDict(dict, resolver): PdfLayerManager

Defined in: src/layers/optionalContent.ts:227

Parse a PdfLayerManager from an /OCProperties dictionary.

Parameters

dict

PdfDict

The /OCProperties dictionary from the catalog.

resolver

(ref) => PdfObject

A function that resolves indirect references.

Returns

PdfLayerManager

A PdfLayerManager instance.

Released under the MIT License.