Pdf - PdfLayerStateOperation

18 Nov 20261 minute to read

Public enum to define the visibility operation applied to a layer by a PdfLayerState.

// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create a layer and its state
let layer: PdfLayer = document.layers.add('Content Layer', true);
let state: PdfLayerState = new PdfLayerState(PdfLayerStateOperation.Off, layer);
// Create a layer-state action
let action: PdfSetOCGStateAction = new PdfSetOCGStateAction([state], true);
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
    page, 'LayerState', { x: 20, y: 20, width: 120, height: 30 }
);
field.text = 'Change layer';
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();
  • Off - Specifies that the layer is turned off.
  • On - Specifies that the layer is turned on.
  • Toggle - Specifies that the current visibility state of the layer is toggled.