On this page
Show & hide PDF layers
Use the getLayers
function to retrieve the OCG layers associated with the document. You can then selectively hide layers.
In the example below, the getLayers
function returns an array of layers. To hide a layer, you can call the setLayers
function, passing an object that includes the ocg property, node property, and visible property. If you need to modify layers in bulk, you can pass an array containing multiple objects. After the call is complete, the page will be redrawn.
javascript
// Get layers.
const layers = await docViewer.getLayers();
// Hide the first and second layers.
docViewer.setLayers([{
node: layers[0].node,
ocg: layers[0].ocg,
visible: 0
}, {
node: layers[1].node,
ocg: layers[1].ocg,
visible: 0
}]);
// Show the first layer.
docViewer.setLayers({
node: layers[0].node,
ocg: layers[0].ocg,
visible: 1
});