Some test text!

Hamburger Icon

Web / Guides / Show/hide layers

Showing & hiding PDF layers using JavaScript

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 with layers. To hide a layer, the visible property can be set to false. You must then call setLayersArray with the modified layers array. Finally, call refreshAll and updateView to clear the page cache and redraw.

}, document.getElementById('viewer'))
  .then(instance => {
    const { documentViewer } = instance.Core;

    documentViewer.addEventListener('documentLoaded', () => {
      const doc = documentViewer.getDocument();

      doc.getLayersArray().then(layers => {
        // Set all layers to not visible
        layers.forEach((layer, index) => {
          layers[index].visible = false;
        // clears page cache
        // redraws

Get the answers you need: Chat with us