Skip to main content
Participating Frequently
July 5, 2023
Answered

How to make multiple layers visible when multiple checkboxes are selected?

  • July 5, 2023
  • 1 reply
  • 4842 views

I have a selection of layers, each made visible when a certain checkbox is selected. The catch is I need multiple layers visible when multiple checkboxes are selected. Whichever layer I last had the mouse over last is the one that shows up in the final result. Currently, each checkbox follows an action whereupon Mouse Enter, it displays a layer.

Since layers do not work the same as they would in photo editing software, how do I allow for two layers to co-exist at the same time? Screenshots are attached of the set-up as it exists.

 

 

 

Correct answer try67

You can use button fields for that, as they can contain an image as their icon, and are much easier to control than layers.

1 reply

try67
Community Expert
Community Expert
July 5, 2023

Layers are not mutually exclusive in PDF files. It's only this (ill-designed) dialog that forces them to work like that.
If you used a script instead you could show (or hide) the layers you wanted to change, while leaving the others as they were.

For example, the following code can be used to set a specific layer (called "Layer1", in this case) as visible when a check-box is ticked, and to hide it when it's unticked. Use it as the Mouse Up event of the check-box:

var ocgArray = this.getOCGs();
for (var i=0; i<ocgArray.length; i++)  {
	if (ocgArray[i].name=="Layer1") {
		ocgArray[i].state=(event.target.value!="Off");
		break;
	}
}

 

However, there is a catch. When the form is cleared, the layer will not become hidden automatically. You will have to do it manually, using a script.

Also, when the file is re-opened, the state of the layer will not be saved, and will revert to its initState setting.

This setting can be changed in Acrobat, but not in Reader. To get it to show/hide in Reader correctly you would need to embed a script in the document that executes when it's opened to restore the last view state of all layers, when it was last saved.

Theo5E95Author
Participating Frequently
July 5, 2023
Is there a smarter way to achieve my desired results without using layers?
Display image for Checkbox Group 1, Group 2, & Group 3, all images stacked
on top of each other each time? Layers seemed to make the most sense until
your explanation.
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 5, 2023

You can use button fields for that, as they can contain an image as their icon, and are much easier to control than layers.