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

Hide all layers

New Here ,
May 21, 2022 May 21, 2022

I have made a multi-page document with forms. Each page has a background image in its own layer. Is it possible to hide them all at the touch of a button? I want the user to be able to choose not to print the background and turn off over 30 layers take time.

TOPICS
Edit and convert PDFs , JavaScript , PDF forms
1.9K
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 ,
May 22, 2022 May 22, 2022

Try following script:

var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
  for (var i in layers) {
    if (layers[i].name==layerName)
      layers[i].state = !layers[i].state;
  }
}

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 ,
May 21, 2022 May 21, 2022

You may be able to achieve this by employing the use of JavaScript, or simply using Acrobat's built-in features, such as radio buttons or checkboxes  to set layer visibility with show or hide state.

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
New Here ,
May 21, 2022 May 21, 2022

I'm not so familiar with JavaScript but after a lot of googling I tried this code

 

var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
for (var i in layers) {
if (layers[i].name==layerName) {
layers[i].state = !layers[i].state;
break;
}
}
}

 

All the layers have the same name, but this did only worked on the page of the check box. The same happend for the built-in feature for hiding layers. I want it to hide all the layers on every page with one click. 

I don't know if it maters but I only have this background layer on every page, no other layers.

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 ,
May 22, 2022 May 22, 2022

Try following script:

var layerName = "Bakgrunn";
var layers = this.getOCGs();
if (layers!=null && layers.length!=0) {
  for (var i in layers) {
    if (layers[i].name==layerName)
      layers[i].state = !layers[i].state;
  }
}
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
New Here ,
May 23, 2022 May 23, 2022

That works exactly like I want it to. Thank you.

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 ,
May 22, 2022 May 22, 2022

This code doesn't hide a layer, it toggles its visibility. If it was hidden it will make it visible, and vice versa.

To actually hide it change this line:

layers[i].state = !layers[i].state;

To:

layers[i].state = false;

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
New Here ,
May 23, 2022 May 23, 2022

Sorry I probably wrote this a little wrong. I wanted a way to toggle the layers visibility on and off.

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 ,
May 23, 2022 May 23, 2022
LATEST

To toggle layers visible or not visible is just easier to employ a pair of radio buttons or checkboxes.

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 ,
May 22, 2022 May 22, 2022

What are the names of the layers?

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
New Here ,
May 22, 2022 May 22, 2022

The name for all layers are "Bakgrunn" 

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