• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript toggle/show layers Acrobat DC

New Here ,
Dec 10, 2019 Dec 10, 2019

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

ex nihil nihilo fit
TOPICS
Acrobat SDK and JavaScript

Views

697

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 10, 2019 Dec 10, 2019

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.

Votes

Translate

Translate
Community Expert ,
Dec 10, 2019 Dec 10, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

Dear try67,

thank you very much! It worked, did not think it was so simple...

 

Cheers

 

Matthias

ex nihil nihilo fit

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

Beware, the state of the layers is not saved at the closing of the document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

Use this to save the OCG state with the PDF

 

layers[i].state = layers[i].initState = true;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

LATEST

I think you mean:

layers[i].initState = true;

And it's important to note that won't work in Reader, only in Acrobat.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines