Copy link to clipboard
Copied
Hello folks,
I need some assistance by toggling the visibility of layers. I am not to familiar with JS yet but i managed at least to show single layers depending on what is selected from a list. The layers hold descriptions in English, German and French language. This layers are shown if i put in the following code into the validation field:
var layers = this.getOCGs();
var v = event.value;
for (var i = 0; i < this.layers.length; i++) {
if (layers[i].name == "Deutsch" && v == "Deutsch") {
layers[i].state = true
}
else if (layers[i].name == "English" && v == "English") {
layers[i].state = true;
}
else if (layers[i].name == "Francais" && v == "Francais") {
layers[i].state = true;
}
else {
layers[i].state = false;
}
}
How do I manage to show another layer named "Hintergrund" (German for Background) all the time, no matter which of the language selections has been made?
Thank you in advance for your kind support!
Matthias
Add this to the top of the if-condition:
if (layers[i].name == "Hintergrund") {
layers[i].state = true
} else if (layers[i].name == "Deutsch" && v == "Deutsch") {
// etc.
Copy link to clipboard
Copied
Add this to the top of the if-condition:
if (layers[i].name == "Hintergrund") {
layers[i].state = true
} else if (layers[i].name == "Deutsch" && v == "Deutsch") {
// etc.
Copy link to clipboard
Copied
Dear try67,
thank you very much! It worked, did not think it was so simple...
Cheers
Matthias
Copy link to clipboard
Copied
Beware, the state of the layers is not saved at the closing of the document.
Copy link to clipboard
Copied
Use this to save the OCG state with the PDF
layers[i].state = layers[i].initState = true;
Copy link to clipboard
Copied
I think you mean:
layers[i].initState = true;
And it's important to note that won't work in Reader, only in Acrobat.