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

harvesting field properties in visual order

Community Expert ,
Apr 13, 2016 Apr 13, 2016

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");


TOPICS
Acrobat SDK and JavaScript
857
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 ,
Apr 13, 2016 Apr 13, 2016

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.

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 ,
Apr 13, 2016 Apr 13, 2016

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.

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 ,
Apr 14, 2016 Apr 14, 2016
LATEST

Correct, you can't sort the fields by tab order. You don't have access to that information.

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 ,
Apr 13, 2016 Apr 13, 2016

‌You can use the rect property of the fields to sort the fields.

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 ,
Apr 13, 2016 Apr 13, 2016

(in combination with the page property)

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