Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
23

Hide show layers across several pages using dropdown selection

Participant ,
Feb 21, 2024 Feb 21, 2024

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);

 

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
642
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 21, 2024 Feb 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2024 Feb 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 22, 2024 Feb 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2024 Feb 22, 2024
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines