Some test text!

Show/hide layerskeyboard_arrow_down

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: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.