Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Web Guides Render layers

Show & hide PDF layers ​

Use the getLayersArray function to retrieve the OCG layers associated with the document. You can then selectively hide layers.

In the example below, the getLayersArray function returns an array of layers. To hide a layer, set its visible property to false and then call the setLayersArray function, passing the modified array. Multiple layers can be modified in one call. After the call is complete, the page will be redrawn.

javascript
const doc = documentViewer.getDocument();

// Get layers.
const layers = await doc.getLayersArray();

// Hide the first and second layers.
layers[0].visible = false;
layers[1].visible = false;
await doc.setLayersArray(layers);

// Show the first layer.
layers[0].visible = true;
await doc.setLayersArray(layers);