Skip to main content
Participant
September 4, 2016
Answered

Keep layers that are shown by javascript in Acrobat

  • September 4, 2016
  • 5 replies
  • 1107 views

Hey guys,

I'm hoping to find an answer to my problem here, as I really don't know what else to try right now...

I did a dynamic form for a company with Adobe Acrobat Pro. If I choose something at a dropdown menu, some new forms and a different layer of the PDF becomes visible. I managed to do all this by using form actions and javascript.

The problem is that I'm not able to keep the layers visible when I'm saving. Is there a possibility that the form stays exactly as it was when I'm saving? This would be really important because the company would use this form for costumers and they need to see what was visible and checked by their costumers of course.

Thanks for the help

Philipp

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

There are two ways of doing it.

The first is to change the layer's initState property, which determines if it shown or not when the file is opened.

This is the easiest way of doing it, but the problem is that this property is read-only in Reader, so unless your file is only used in Acrobat it's not really feasible.

The second one is to use a script to show/hide the layers based on some logic when the file is opened, using a doc-level script.

The logic will probably be the same as what you're already using for your drop-downs and other fields, you just need to adjust it so that it gets executed when the file is opened, not just when the values of these fields is changed.

5 replies

exelrex3Author
Participant
September 6, 2016

Thank you very much for the help. The document level script was exactly what I needed

Have a nice day everyone.

Inspiring
September 4, 2016

I use buttons for things like this instead of layers. I find they're easier to work with, faster, and you don't have to deal with the problem you're having. So rather than show/hide layers, you show/hide read-only buttons that are set up to display the content you want. Set them at the top of the tab order. Using hierarchical field names make control of the fields simple. The layer approach also has less support in non-Adobe PDF viewers. One thing this means is that an initialization script might not get executed (or be fully supported) and the display will be wrong.

try67
Community Expert
Community Expert
September 4, 2016

The main problem with buttons is they don't have an opacity setting, so you can't use them to overlay items one on top of another, which is usually what people do with layers.

Inspiring
September 4, 2016

That really depends on how the button icon content is created. Often times a PDF page will have what is effectively an opaque white background, but it doesn't have to. I usually wouldn't have multiple buttons overlayed and set to display at the same time though.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 4, 2016

There are two ways of doing it.

The first is to change the layer's initState property, which determines if it shown or not when the file is opened.

This is the easiest way of doing it, but the problem is that this property is read-only in Reader, so unless your file is only used in Acrobat it's not really feasible.

The second one is to use a script to show/hide the layers based on some logic when the file is opened, using a doc-level script.

The logic will probably be the same as what you're already using for your drop-downs and other fields, you just need to adjust it so that it gets executed when the file is opened, not just when the values of these fields is changed.