How to toggle visibility of a PDF layer in PDF.js

I have a PDF file with multiple layers. In Adobe Acrobat I can toggle the visibility of those layers via JavaScript included in the PDF. PDF.js, like many others viewers do not support JS within PDFs. But the layers are diplayed in the side pane of the viewer – where I can toggle the visibility.
How can I toggle the visibility via JS, triggered by a button outside of the viewer?

enter image description here

20 thoughts on “How to toggle visibility of a PDF layer in PDF.js”

Leave a Comment