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

Loop edit fields

Community Expert ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

Here is a sample script that loop into form fields to edit some properties:

for (var i = 0; i < numFields; i++) {

    var fName = getNthFieldName(i);

    var f = getField(fName);

    if (f.type === "text") {

        f.textFont = font.Times;

        f.textSize = 9;

    }

}

It works fine as long as there is no field using the Acrobat Forms Field Hierarchies.

(text.0, text.1, text.2, and so on)

If there are any in the form I get this error: f is null

Capture 2.png

My question is: Is it possible to use a script that can edit properties by looping into all forms fields, using the Acrobat Forms Field Hierarchies or not?

TOPICS
Acrobat SDK and JavaScript

Views

682

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Mar 01, 2018 Mar 01, 2018

I've seen this happen with corrupt fields, especially those that were created in InDesign. Karl's recommendation should help solve it.

Votes

Translate

Translate
Community Expert ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

I've never had a problem with this. I would add the following for debugging purposes: Add a line that prints which form field is being processed to see what the name of the field is that triggers the error. You can also add a check to the "if" command to make sure that you are not processing a null field:

if (f != null && f.type == "text) {

....

}

Votes

Translate

Translate

Report

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 ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

I've seen this happen with corrupt fields, especially those that were created in InDesign. Karl's recommendation should help solve it.

Votes

Translate

Translate

Report

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 ,
Mar 02, 2018 Mar 02, 2018

Copy link to clipboard

Copied

I made these forms fields with Acrobat Pro DC, files was not made with InDesign.

Using Karl's debug tip I can see that the loop works fine, processing fields in alphabetical order until the first field that use the hierarchical naming.

Then it returns : f is null and it stop processing.

Votes

Translate

Translate

Report

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 ,
Mar 02, 2018 Mar 02, 2018

Copy link to clipboard

Copied

Can you share the file and the full code you're using?

Votes

Translate

Translate

Report

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 ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

LATEST

Good point: it's a file issue.

I cannot share it but it was made from Powerpoint and form fields were added using PDF Converter.

With Acrobat Pro I removed some listboxes and form fields and replace them by new ones using the hierarchical naming.

This is why I wanted to batch edit fields that were previously created since they don't use the right font.

So I found a workaroud: I cut my hierarchical fields, I process the loop to edit previously created fields, and then I paste my fields back.

😉

Thank you!

Votes

Translate

Translate

Report

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