Copy link to clipboard
Copied
I have made a multi-page document with forms. Each page has a background image in its own layer. Is it possible to hide them all at the touch of a button? I want the user to be able to choose not to print the background and turn off over 30 layers take time.
Copy link to clipboard
Copied
Try following script:
var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
for (var i in layers) {
if (layers[i].name==layerName)
layers[i].state = !layers[i].state;
}
}
Copy link to clipboard
Copied
You may be able to achieve this by employing the use of JavaScript, or simply using Acrobat's built-in features, such as radio buttons or checkboxes to set layer visibility with show or hide state.
Copy link to clipboard
Copied
I'm not so familiar with JavaScript but after a lot of googling I tried this code
var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
for (var i in layers) {
if (layers[i].name==layerName) {
layers[i].state = !layers[i].state;
break;
}
}
}
All the layers have the same name, but this did only worked on the page of the check box. The same happend for the built-in feature for hiding layers. I want it to hide all the layers on every page with one click.
I don't know if it maters but I only have this background layer on every page, no other layers.
Copy link to clipboard
Copied
Try following script:
var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
for (var i in layers) {
if (layers[i].name==layerName)
layers[i].state = !layers[i].state;
}
}
Copy link to clipboard
Copied
That works exactly like I want it to. Thank you.
Copy link to clipboard
Copied
This code doesn't hide a layer, it toggles its visibility. If it was hidden it will make it visible, and vice versa.
To actually hide it change this line:
layers[i].state = !layers[i].state;
To:
layers[i].state = false;
Copy link to clipboard
Copied
Sorry I probably wrote this a little wrong. I wanted a way to toggle the layers visibility on and off.
Copy link to clipboard
Copied
To toggle layers visible or not visible is just easier to employ a pair of radio buttons or checkboxes.
Copy link to clipboard
Copied
What are the names of the layers?
Copy link to clipboard
Copied
The name for all layers are "Bakgrunn"
Find more inspiration, events, and resources on the new Adobe Community
Explore Now