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

Create a drop down list populated with all folders in a network location.

Community Beginner ,
Jun 25, 2025 Jun 25, 2025

Hi All,

 

We have a PDF form which we print and manually and fill in but I am looking at making it interactive.

 

I would like to have a drop-down to select a folder from our network in one section of the form.

 

I know this cannot be done in Acrobat alone with JavaScript, but after a bit of searching online it can be achieved by creating an external file.

 

So far I have

  1. Created a Windows PowerShell Script to create a .txt file which contains all the folders in the Network location. The plan is to run this at regular intervals to keep it up-to-date.
  2. Created a .js file in C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts that reads a text file from disk and sets a dropdown field’s items

3. Created a dropdown on the PDF but this is where it's falling over.

 

In the properties of the drop-down down I have selected 'On Mouse down' and set it to run a Java Script.

In the java script i have entered trustedImport();

 

After all this when i run it and try the Drop-down, nothing shows in the drop-down

 

Anyone done this or something similar? Javascript in not my thing so i may be doing something astoundingly obvious and it's not quite a straight forward as i thought.

TOPICS
JavaScript , PDF forms
176
Translate
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 25, 2025 Jun 25, 2025

What script do you use ?

Translate
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 ,
Jun 25, 2025 Jun 25, 2025

This is the script i'm using 

 

trustedImport = app.trustedFunction(function() {
app.beginPriv();

var path = "/Nas02/Livedata/folderlist.txt";
var stream = util.readFileIntoStream(path);
var content = util.stringFromStream(stream);
var folders = content.split("\n");

var f = this.getField("folderDropdown");
if (f) {
f.setItems(folders);
}

app.endPriv();
});

trustedImport(); // call the function

Translate
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 25, 2025 Jun 25, 2025

You can call the function at document open.

Translate
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 25, 2025 Jun 25, 2025
LATEST

There are a few problems with your script.  The main one is that you shouldn't use a variable name that is already defined.  When you call path you are calling the path to the current PDF document, which will read a stream from the PDF itself.  Change the two instances of path to pth.  Next, when you split a text column with \n or \r it splits the values but also leaves the line breaks in the result.  That will give you line breaks in the dropdown values.  A workaround is to create a new array, loop through the existing one, and push the values (while removing the line breaks) into the new array  and use the new array to set the dropdown items.  Next, you should use event.target instead of this.getField("folderDrodown") since the script is in the "folderDropdown" field.  However, it would be easier to call the function in a document level script so the dropdown items load as soon as the document opens, as @Bernd Alheit pointed out.  It's good practice to define the document with a variable in the function.  Here's the script with the corrections:

trustedImport = app.trustedFunction(function(oDoc) {
app.beginPriv();
var pth = "/Nas02/Livedata/folderlist.txt";
var stream = util.readFileIntoStream(pth);
var content = util.stringFromStream(stream);
var folders = content.split("\n");
var aray=[];
for(i in folders)
{aray.push(folders[i].replace("\r",""))}
var f = oDoc.getField("folderDropdown");
if (f) {
f.setItems(aray);
}
app.endPriv();
});
trustedImport(this);//

Note, the function is called from a document level script.  If it's called from the field, change oDoc.getField("folderDropown") to event.target.

Translate
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 25, 2025 Jun 25, 2025

This is how I would approach it:

1)  Create a hidden text field in the form ("Row"), with the following validation script:

this.getField("Items").value+=event.value+"\r";

2) Create a second hidden text field that is multiline and allows scrolling long text ("Items").

3) The mouse down action of the dropdown calls a trusted function from the JavaScript folder that clears "Items" and imports all rows of the text file to "Row".

4)  The mouse down action of the dropdown creates an array from the rows in "Items" and sets the items of the dropdown with this array:

var aray=this.getField("Items").value.split("\r"); aray.pop();

event.target.setItems(aray);

The following article, while not exactly the same (the text file list is PDF files, not folders), outlines in detail the steps above.

https://pdfautomationstation.substack.com/p/how-to-create-your-own-action-batch

Translate
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 ,
Jun 25, 2025 Jun 25, 2025

I will have a read, Thanks for the reply.

Translate
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