Skip to main content
Wayne!
Participating Frequently
July 7, 2023
Question

Show hide layers from a dropdown in Adobe Acrobat! Help Please!!!

  • July 7, 2023
  • 1 reply
  • 480 views

Show hide layers from a dropdown in Adobe Acrobat!

 

I have implemented the script below that may have some errors - but I have limited knowledge of JavaScript. I have adapted this script and seems to work locally however when I send it to the client it fails! Are there any obvious errors in the following?

 

Any help is much appreciated!!!

 

 

var layers = this.getOCGs();

var v = event.value; 

for (var i = 0; i < this.layers.length; i++) {

    if (layers[i].name == "Blank" && v == "BlankOption") {

        layers[i].state = true;

    }

    else if (layers[i].name == "Form1" && v == "Option1") {

        layers[i].state = true;

    }

    else if (layers[i].name == "Form2" && v == "Option2") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form3" && v == "Option3") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form4" && v == "Option4") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form5" && v == "Option5") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form6" && v == "Option6") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form7" && v == "Option7") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form8" && v == "Option8") {

        layers[i].state = true;

    }

        else if (layers[i].name == "Form9" && v == "Option9") {

        layers[i].state = true;

    }

    else if (layers[i].name != "BG-IMAGE"){

        layers[i].state = false;

    }

}

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
July 7, 2023

It may not be the script. It might be the viewer the client is using.  JavaScript is not well supported in most viewers. The OCG scripting functions are even less supported. 

Ask them how they are opening the PDF. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Wayne!
Wayne!Author
Participating Frequently
July 7, 2023

I did ask if he was using Adobe Reader! I comiitted to a simple form and then the goals posts were moved!! I think there is a LayerConfig (Nesa Nurani) to save the layer states that might also complicate things  

 

I think i'm out of my depth!! 

Thom Parker
Community Expert
Community Expert
July 7, 2023

Adobe Acrobat Reader supports all of the necessary JavaScript. So if the form was viewed in Reader the layer states would change with the dropdown selection, the same as in Pro.  Saving states so they are restored when the document is opened is a different issue not addressed by the code you've presented. 

Is the client failure that the layers do not change with the dropdown selection? or that layer visibility does not stick?

You should also find out exactly what viewer they are using. 

  

 

 

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