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
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?
I've seen this happen with corrupt fields, especially those that were created in InDesign. Karl's recommendation should help solve it.
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) {
....
}
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.
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.
Copy link to clipboard
Copied
Can you share the file and the full code you're using?
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!