Skip to main content
Robb Nemo
Inspiring
February 21, 2024
Answered

Hide show layers across several pages using dropdown selection

  • February 21, 2024
  • 1 reply
  • 996 views

I've created a PDF document containing serveral posters which all contain an area for a departmental branding. I want to be able to change the branding information across all of the pages in one hit by selecting the department from a (non printing) dropdown box.

I've managed to achieve this on a single page by using layers and the following javascript to show/hide the different departments. However, this doesn't change the layer visibility across all of the pages. Does anyone out there know how this can be done or if it's even possible?

var layers = ["Dept1","Dept2","Dept3","Dept4","Dept5","Dept6"];

var docOCGs = this.getOCGs();

for( i=0 ; i<docOCGs.length ; i++){
    var val = layers.indexOf(docOCGs[i].name);
    if(val >=0){
        layers[val] = docOCGs[i];
    }   
}

function SetFieldValues (item){
    for( i=0 ; i<layers.length ; i++){
        layers[i].state = false;
        if(layers[i].name == item){
            layers[i].state = true
        } 
    }
}

SetFieldValues (this.getField("select").value);

 

This topic has been closed for replies.
Correct answer Thom Parker

The layers need to be added to the PDF differently.   The layers tool adds each image was separately.   But the Watermark tool add the same image as a layer to every page. To add multiple layers to every page just rename the watermark layer. 

Read this article:

https://acrobatusers.com/tutorials/create_use_layers/

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 21, 2024

The layers need to be added to the PDF differently.   The layers tool adds each image was separately.   But the Watermark tool add the same image as a layer to every page. To add multiple layers to every page just rename the watermark layer. 

Read this article:

https://acrobatusers.com/tutorials/create_use_layers/

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Robb Nemo
Robb NemoAuthor
Inspiring
February 22, 2024

Thanks Thom, that's a gret idea and it works a treat.

At first when I used the "Update" option in the Watermark section, choosing a diferent saved watermark didn't change anything, but I found that using the "add" option , choosing "Replace Existing" and then selecting one of my saved watermarks from the "Saved Settings" dropdown, is the way to go 🙂

 

Just pushing the idea, and to make it easier for others in my office who might not be as familiar with delving into opening and editing of the PDF.... is there a way to use a Forms dropdown option (similar to the method I discussed in my original post) to change the watermark?

Thom Parker
Community Expert
Community Expert
February 22, 2024

The watermarks are "Layers" that are named "watermark".  You can add multiple layers by alternately renaming the "watermark" to a custom name and then adding a new watermark.

The issue with watermarks is that they are not immediately visible on the Layers Tab.  To make them visible, run this code in the console window.

 

this.setOCGOrder(this.getOCGs());

 

After this you'll be able to change the "watermark" name to something else. And then you can use the dropdown to control visibility. 

 

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