Loop edit fields

Adobe Community Professional ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

247

Likes

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

Loop edit fields

Adobe Community Professional ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

248

Likes

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
Mar 01, 2018 0
Adobe Community Professional ,
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) {

....

}

Likes

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
Reply
Loading...
Mar 01, 2018 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Mar 01, 2018 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Mar 02, 2018 0
Most Valuable Participant ,
Mar 02, 2018

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 02, 2018 0
Adobe Community Professional ,
Mar 03, 2018

Copy link to clipboard

Copied

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!

Likes

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
Reply
Loading...
Mar 03, 2018 0