Skip to main content
Participant
Jun 25, 2025 10:54 AM UTC
Question

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

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.

6 replies

PDF Automation Station
Community Expert
Community Expert
Jun 25, 2025 12:01 PM UTC

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
Participant
Jun 25, 2025 12:14 PM UTC

I will have a read, Thanks for the reply.

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 25, 2025 11:37 AM UTC

What script do you use ?

Translate
Participant
Jun 25, 2025 12:14 PM UTC

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
Bernd Alheit
Community Expert
Community Expert
Jun 25, 2025 1:37 PM UTC

You can call the function at document open.

Translate