Skip to main content
Participant
May 31, 2020
Question

this.getField array

  • May 31, 2020
  • 1 reply
  • 5428 views

Hi guys,

I am fairly new to Java so I apologise ahead of time if the problem is trivial. I am attempting to import an array from a drop-down list which I then wish to export as a .txt file. I can succesfully use this.getField to acquire the fields value but I'd like to be able to acquire all the fields that the drop-down list contains to an external text file. Is it possible to obtain all values of a drop-down box or even a list? 

Thanks

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
June 1, 2020

I believe that you can do most, if not all of what you want, but there are some issues.

First, there is some terminology that is important for communicating to us what it is you want to do.

Acrobat uses JavaScript as it's internal programming language, same as HTML does.  Java is a very different thing. 

Dropdown lists do not contain other field, they contain a list of items. I believe it is this list of items you want to acquire?

 

You can read about the basics of list field programming here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

You'll see that list fields have a function named "getItemAt()". This is the function you'll need to use to acquire the list of items in the dropdown. Here's the Acrobat JavaScript reference entry for it.  

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_methods.htm%23TOC_getItemAtbc-12&rhtocid=_6_1_8_31_2_11

 

That should get you started.

Next, a Script in Acrobat can't actually write to a text file on the user's hard drive. But there are some options depending the specifics of your process.  

So, is this a one time thing? or does it need to be done repeatedly? Is it just you, or is this something other people will also need to do?

 

Let us know.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
saf786Author
Participant
June 2, 2020

Hi Thom, 

 

Thanks for the prompt response,  I have currently had success in using the following code to be able to write to a text file, on the hard drive:

// set up output text
var TEMP_FIELD_NAME = "testHeader"
var textValue = this.getField("list");

// add a temporary text field
var f = this.addField(TEMP_FIELD_NAME, "text", 0, [30,30,100,20]);
f.value = textValue;
// export field name and value to defined file
this.exportAsText({aFields: TEMP_FIELD_NAME, cPath: "test-stock.txt"});
// remove text field
this.removeField(TEMP_FIELD_NAME);
// notify when done
app.alert("Done!");

I guess the purpose of the script ultimately would be to write a text file which contains a list of all options contained in a dropdown menu and be able to retrieve them and update the drop-down list. If possible I would like to use an array at getItemAt([0, n])

Thom Parker
Community Expert
Community Expert
June 2, 2020
How are you running the code you posted? Eventually you'll need to create an automation tool. So is this something you are going to do repeatedly? You want to save the list items in a text file, then retrieve them and repopulate the text item list? Will this text file be managed outside of Acrobat? Does it need to be in a particular format so that it can be accessed by say Excel? In order to make reasonable suggestions I'll need to get an idea of the desired workflow.
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often