Skip to main content
Participating Frequently
September 5, 2024
Question

Layers not toggling with Javascript in Acrobat Reader

  • September 5, 2024
  • 1 reply
  • 361 views

I have this document with two layers, one to show Imperial Units and one to show Metric Units

 

I have two radio buttons in a group to toggle the layers according to the user selection. Imperial is the default when document opens.

If the user selects the radio button "Metric" the layers toggle to show the change:

I am using this code:

var ocgArray = this.getOCGs();
for (var i=0; i < ocgArray.length; i++) {
    if (ocgArray[i].name == "Imperial Units") {
        ocgArray[i].state = true;
    } // end-if
    if (ocgArray[i].name == "Metric Units") {
        ocgArray[i].state = false;
    } // end-if
} // end-for

This works fine in Acrobat (Pro) but users are reporting it doesn't work in Acrobat Reader. When the "Metric" radio button is selected, nothing happens... See attached file below.

Can't see what I'm missing... Also, I don't have Reader to test, so I have to send it over to a colleague!

Thank you!

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
Community Expert
September 5, 2024

This should work with Reader.  Are they perhaps opening the form in a web browser where the script would not work?

ArturoFCAuthor
Participating Frequently
September 5, 2024

My colleague tester even reported that after clicking the radio buttons several times, Reader crashed... 😞