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

this.getField array

New Here ,
May 31, 2020 May 31, 2020

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

TOPICS
PDF forms
5.1K
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 ,
May 31, 2020 May 31, 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_Acro...

 

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Jun 02, 2020 Jun 02, 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])

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 02, 2020 Jun 02, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Jun 02, 2020 Jun 02, 2020

The list will only be accessible via Acrobat. The workflow would be as follows:

1. pdf file containing script is opened and retrieves the text, this will more than likely by assigned to a button that holds the function to retrieve text data. 

2. If the drop down list does not contain what the user requires, a custom entry in the drop down list can be made (and comitted to the drop down list?)

3. The 'update list' action will be assigned to a button which can then update the entire list as appropriate appending new values as required ensuring that the drop down list is always updated

 

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 02, 2020 Jun 02, 2020
LATEST

Ok, so anything that saves the data outside the form will work? Do other users need to access this data? Or is it just for a single person? Is this happening in a controlled environment? i.e. can you install scripts on the user's system?

 

All JavaScript functions that write to the user's file system require privilege. Which is why I asked how the script is being run now, because the script you posted will not work when run from inside a PDF. 

Basically unless you have some control over the user's system you can't use a function that writes to the file system.  

Read about privilege here:

https://www.pdfscripting.com/public/Trust-and-Privilege-in-Acrobat-Scripts.cfm?sd=40 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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