Copy link to clipboard
Copied
Hi all, I'm very much a javascript novice but am hoping someone can point me in the right direction.
I'm looking for an alternative to auto calculation in my PDFs due to lag issues, and am trying to see if I can have my documents calculate sections/chapters only when a button is pressed. These documents have a lot of fields (some over 1000) and so it would be nice if the code could do a search of fields and add to a points counter when I find all the fields I want to include, rather than making a huge array of field. Think Section Point01, Section Point02, etc. So I want to look for all the instances of "Section01 Point".
I tried one solution I saw that used (.indexOf("Section01 Point") > -1), but nothing happened when I tested the output (trying to find the point of failure is another issue entirely, I'm finding). I'm a bit wary of just searching for standard JS solutions as I know acrobat doesn't use all of the latest ones.
Any suggestions are appreciated. 🙂
Copy link to clipboard
Copied
You can use this code to do that:
var counter = 0;
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f==null) continue;
if (f.name.indexOf("Section01 Point") > -1) {
counter++;
}
}
console.println("There are " + counter + " fields in " + this.documentFileName);
If you run it in an Action you'll be able to see the full results in the JS Console at the end of the process.
Copy link to clipboard
Copied
You can use this code to do that:
var counter = 0;
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f==null) continue;
if (f.name.indexOf("Section01 Point") > -1) {
counter++;
}
}
console.println("There are " + counter + " fields in " + this.documentFileName);
If you run it in an Action you'll be able to see the full results in the JS Console at the end of the process.
Copy link to clipboard
Copied
Oh this is great, thank you! I hadn't figured out how to use the acrobat JS console either so that was helpful. With some tinkering I was able to get the code to do exactly what I needed. Appreciate the fast answer!