Copy link to clipboard
Copied
My apologies in advance; I suspect this is not an Acrobat question but a "How do I write Javascript?" question.
I have been trying to write a script to collect tooltips for translation, from a multipage Acrobat form. However, I am a pretty terrible scripter - I do more copy/pasting from forums than actual writing of code. I was using getNthFieldName to return all of the tooltips (userName) to the console, which I was able to do successfully. However, it returns them in alphabetical order according to the name of the field. This is not really useful to me; I would like to spit out the tooltips in some other order. Because of the way that my translator works here, I would very much like to spit them out to the console in visual top-down, left-right order. My research indicates that there is no published description of any way to alter the way that getNthFieldName returns values.
How would someone do this? I'm kind of at a loss. I suspect that some kind of for loop using getField and returning the values to an array would work, but I'm not sure how to use getField to get all the fields. All of the examples I've found use something like getField("This is a field with a unique name in my document");
Copy link to clipboard
Copied
This is not a simple task, but it's doable. The approach would be to indeed create an array with the field objects directly, or the field names (using getNthFieldName) and then sort that array using a custom sort function. See: JavaScript Array sort() Method
Once the array is sorted you can just iterate over it using a for-loop and print out the userName property for each field, as you did before.
Copy link to clipboard
Copied
The approach would be to indeed create an array with the field objects directly, or the field names (using getNthFieldName) and then sort that array using a custom sort function. See: JavaScript Array sort() Method
Well, there are plenty of sorting options once you've sucked out the field names in alpha order into an array, but none of them are "according to the tab order of the fields, set laboriously and manually by someone who needed the fields to read in a logical order for blind people."
I could use rect - but then I looked at some pages really closely, and saw that some of the logical order diverges (reasonably) from the top-down left-right supposition I had made. Only harvesting them in tab order will work, and I'm not sure if doing so is possible with JS at all.
Copy link to clipboard
Copied
Correct, you can't sort the fields by tab order. You don't have access to that information.
Copy link to clipboard
Copied
‌You can use the rect property of the fields to sort the fields.
Copy link to clipboard
Copied
(in combination with the page property)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now