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
In case someone needed to accomplish this, I got a solution from nesa nurani
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(
...
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.
Copy link to clipboard
Copied
In case someone needed to accomplish this, I got a solution from nesa nurani
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);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can use the direct link to NesaNurani provided by PixelBlur and message directly.
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
Copy link to clipboard
Copied
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!