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
Comment review and collaborate PDF, Create PDFs, General troubleshooting, How to, JavaScript, PDF forms, Standards and accessibility

Views

74

Likes

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  Create dropdown field and name it "LayerConfig", make it hidden and read only. 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 saveLayerConfi...

Likes

Translate

Translate
Adobe Community Professional ,
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.

Likes

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

LATEST

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

 

Likes

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