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

Searching fields for those with a certain name sequence?

Explorer ,
Oct 27, 2023 Oct 27, 2023

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. 🙂

TOPICS
General troubleshooting , How to , JavaScript , PDF , PDF forms

Views

150

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 , Oct 28, 2023 Oct 28, 2023

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.

Votes

Translate

Translate
Community Expert ,
Oct 28, 2023 Oct 28, 2023

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.

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
Explorer ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

LATEST

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!

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