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

Javascript to toggle layer visibility doesn't work on pages created from page templates

Community Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

I have a RPG character sheet with a toggle switch for a layer visibility. It works great on the main document pages but when I add new pages from templates the script doesn't work on the new pages.
Im using this script to toggle the visibility:

var layers = this.getOCGs();
for(var i=0;i<this.layers.length;i++) {
    if(layers[i].name == "Extras") {
        layers[i].state = !(layers[i].state);
    }
} 

 

TOPICS
PDF forms

Views

690

Translate

Translate

Report

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

correct answers 3 Correct answers

Community Expert , Oct 14, 2020 Oct 14, 2020

Templates and layers are incompatible: templates ignore layers.

Votes

Translate

Translate
Community Expert , Oct 15, 2020 Oct 15, 2020

You can add layers in a template page, but it will spawn a "flat" page with all layers merged.

Votes

Translate

Translate
Community Expert , Oct 15, 2020 Oct 15, 2020

I took a quick look at this. Page spawing works by copying all the page contents for the template page into a single XObject. Which makes sense. But it makes new copies of all the indirect objects, and most OCGs are added as Form XObjects. So, the OCG still exists on the newly spawned page, but is now disconnected. In fact it's a new OCG with the same name.  I think this is a bit of a bug. The spawn fuction should better manage the OCGs. It should either not make a new copy of the OCG dicitonary

...

Votes

Translate

Translate
Community Expert ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Do those pages have layers, too?

Votes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Yes. They are made in the same document on Illustrator. The extras layer is named the same on all pages.

Votes

Translate

Translate

Report

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 ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

The question is whether the layer gets included in the Template object and then spawned to the new pages... I haven't tested that before. It's an interesting question. Can you share a sample file?

Votes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Sadly I cannot share it because it's not yet officially released. I'll do a mockup with same funtionality later.


The funny thing is when I go to Organize Pages and manually restore the templates to document, the layers work normally.

 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

I have mockup version behind MEGA-link: Mockup test 

Votes

Translate

Translate

Report

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 ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Templates and layers are incompatible: templates ignore layers.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Well, that's a shame. 😞
I was hoping to make some cool character sheet appearance switches but with this knowledge I'll just do different versions of the same sheet.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Can I first create a page from template and then add a layer with content to it or is it locked even after creation?

Votes

Translate

Translate

Report

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 ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

That should be possible, yes.

Votes

Translate

Translate

Report

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 ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

You can add layers in a template page, but it will spawn a "flat" page with all layers merged.

Votes

Translate

Translate

Report

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 ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

LATEST

I took a quick look at this. Page spawing works by copying all the page contents for the template page into a single XObject. Which makes sense. But it makes new copies of all the indirect objects, and most OCGs are added as Form XObjects. So, the OCG still exists on the newly spawned page, but is now disconnected. In fact it's a new OCG with the same name.  I think this is a bit of a bug. The spawn fuction should better manage the OCGs. It should either not make a new copy of the OCG dicitonary, or it should add the new copy to the OC Properties at the top level so Acrobat knows about it. Leaving dangling OCGs around seems like a bad practice. 

 

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

Votes

Translate

Translate

Report

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