Skip to main content
Participant
March 1, 2025
Answered

radio button to make one of several ocg watermark layers visible and make other ones invisible

  • March 1, 2025
  • 2 replies
  • 294 views

I've got a stack of watermark layers that I can make visible/invisible with a checkbox, but I'd like to look into using a radiobox instead. I can set the buttons up so that they are grouped and set to you can only select one at a time and each button has its own export string.

 

I'd like to know how you take these values to make one layer visible and the others transparent.

Correct answer AnandSri

Hello!

 

I hope you are doing well. 

 

Have you tried the suggestions shared by our community product experts? You may also try the following steps and let us know if that works for you: 

 

Create Radio Buttons:

  • Open the PDF in Acrobat and go to Tools > Prepare Form.
  • Add radio buttons for each watermark layer. Name them appropriately to reflect the layers they control

Set JavaScript Actions:

  • Use JavaScript to control the visibility of the layers. For each radio button, set actions for MouseEnter and MouseExit to show and hide layers:
var layers = this.getOCGs();
for (var i = 0; i < layers.length; i++) {
    layers[i].state = (layers[i].name == https://adobe.ly/3FW37GQ.value);
}


This script ensures that only the selected layer is visible.

Assign Export Values:

  • Assign export values to each radio button corresponding to the layer names. This helps the script identify which layer to show

Test and Adjust:

Thanks,

Anand Sri.

2 replies

AnandSri
AnandSriCorrect answer
Legend
April 8, 2025

Hello!

 

I hope you are doing well. 

 

Have you tried the suggestions shared by our community product experts? You may also try the following steps and let us know if that works for you: 

 

Create Radio Buttons:

  • Open the PDF in Acrobat and go to Tools > Prepare Form.
  • Add radio buttons for each watermark layer. Name them appropriately to reflect the layers they control

Set JavaScript Actions:

  • Use JavaScript to control the visibility of the layers. For each radio button, set actions for MouseEnter and MouseExit to show and hide layers:
var layers = this.getOCGs();
for (var i = 0; i < layers.length; i++) {
    layers[i].state = (layers[i].name == https://adobe.ly/3FW37GQ.value);
}


This script ensures that only the selected layer is visible.

Assign Export Values:

  • Assign export values to each radio button corresponding to the layer names. This helps the script identify which layer to show

Test and Adjust:

Thanks,

Anand Sri.

PDF Automation Station
Community Expert
Community Expert
March 1, 2025

If you did it with check boxes it is exactly the same with radio buttons.   Create the radio buttons on another PDF, name them exactly the same as the check boxes and copy the scripts to them.  Remove the check boxes from original PDF, then copy the radio buttons back.  This article explains how to do it with check boxes:

https://pdfautomationstation.substack.com/p/check-boxes-that-show-and-hide-pdf-c81