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

Acrobat DC - Fillable form uses layers-after filled and saved, need to have the layers filled show

New Here ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Hello,

I am working on a form for new vendors to fill in (see attachment). I am not sure if I am using the right approach for this; I am open to ideas, but I feel it can work. I may just be missing something. Everything seems to work out great, except for one thing. Let me break it down.

 

A vendor will begin filling out the form by addressing the initial prompt to determine if they are a large or small business. Upon determining, new prompts and fields appear based on their selection, I am achieving this by using the selected radio box and show layer visibility as well as show and hide specific fields; I've also added a print and submit button, but I can omit these if needed, the brief did not ask for this, just something I threw in.

 

My problem is, I have the layers "default state" as off; I do this so when the form is initially opened, these layers are not visible. However, when the form is opened from a saved state (submitted by the vendor), the selected layers from the field prompts are turned off, except for the user fields, which is good. How can have the layers that should be turned on be on when the PDF is reopened? I am open to any new ideas.

 

John

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms , Standards and accessibility

Views

921

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 1 Correct answer

New Here , Mar 12, 2021 Mar 12, 2021

In case someone needed to accomplish this, I got a solution from nesa nurani 

 

  1. Create dropdown field and name it "LayerConfig", make it hidden and read only.
  2. create Document level script: While in "Prepare form" tool press CTRL+D or select Javascript tool and from toolbar select "Document level JavaScript"


Name script (name is not important) and click "add", now delete everything that is inside that window and paste this code and thats it, of course save file with code 🙂

 

 

function saveLayerConfig(
...

Votes

Translate

Translate
Community Expert ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

I think you may need to employ some JavaScript and declare a couple of  conditions to handle the hidden or visible state of those layers.

 

This is briefly documented with some script exanples in the AcrobatDC JavaScript API Reference. 

 

For instance, According to the reference in page 509, there is a property "initState" that you can implement in with your script to set the initial on or off state of your document 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
New Here ,
Mar 12, 2021 Mar 12, 2021

Copy link to clipboard

Copied

In case someone needed to accomplish this, I got a solution from nesa nurani 

 

  1. Create dropdown field and name it "LayerConfig", make it hidden and read only.
  2. create Document level script: While in "Prepare form" tool press CTRL+D or select Javascript tool and from toolbar select "Document level JavaScript"


Name script (name is not important) and click "add", now delete everything that is inside that window and paste this code and thats it, of course save file with code 🙂

 

 

function saveLayerConfig(doc) {
  
    var activeLayers = [];

    var ocgArray = doc.getOCGs();
    for (var i = 0; i < ocgArray.length; i++) {
        if (ocgArray[i].state == true) {
            activeLayers.push(ocgArray[i].name);
        }
    }

    var f = doc.getField("LayerConfig");

    if (f != null) {
        f.clearItems();
        f.setItems(activeLayers);
    }
}

function isInArray(val, arr) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == val)
            return true;
    }
    return false;
}


function restoreLayerConfig(doc) {
    var activeLayers = [];

   
    var f = this.getField("LayerConfig");

    if (f != null) {

        for (var i = 0; i < f.numItems; i++) {
            activeLayers.push(f.getItemAt(i));
        }

        var ocgArray = doc.getOCGs();
        for (var i = 0; i < ocgArray.length; i++) {

            ocgArray[i].state = isInArray(ocgArray[i].name, activeLayers);
            activeLayers.push(ocgArray[i].name);
        }
    }
}

restoreLayerConfig(this);

 

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
New Here ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

I tried following these steps for my project but it only hid all the layers.

 

Is there something I am doing wrong. Hope Nesa from Adobe can help me....

 

 

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

You can use the direct link to  NesaNurani provided by PixelBlur and message directly.

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 ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

James-w-b

I was also looking for a solution to this issue, and found out why this wasn't working.... It seems like Nesa's solution is missing the last step. See this link for details in creating a WillSave document action.....at the very bottom of the post.

 

https://answers.acrobatusers.com/Turn-layer-AND-save-layer-state-q164843.aspx 

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
New Here ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

LATEST

Question: is the second document script simply: saveLayerConfig(this); 

OR 

are you supposed to replace a piece of the original document script with this script? I am super new to scripts so I am hoping to understand word for word what each document script is supposed to read as and if I need to add any additional information that is specific to my PDF in the scripts as well.

 

Thanks! 

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