Skip to main content
Participating Frequently
October 21, 2022
Answered

Script to check all checkboxes at once in a given document

  • October 21, 2022
  • 1 reply
  • 1674 views

Hi,

I have some 50-60 page document and i want to check all checkboxes using one single script.. How can i do that?

Thank you

This topic has been closed for replies.
Correct answer try67

this is the code that i typed

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="checkbox") f.checkThisBox(0, true);
var nPgMin = 0, nPgMax = 4;
var oFld = this.getField("xxx");
var aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
var bOnPage = aPgs.some(a=> a>=nPgMin && a<=nPgMax);
}

 this doesn't seem to work.please help


If they are all individual fields then it's quite easy to do, actually. You don't need to sort them or anything like that. Just change this line:

if (f.type=="checkbox") f.checkThisBox(0, true);

To this:

if (f.type=="checkbox" && f.page<=4) f.checkThisBox(0, true);

1 reply

try67
Brainiac
October 21, 2022

You can do it using this code:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="checkbox") f.checkThisBox(0, true);
}
Participating Frequently
October 21, 2022

P.S -Let's say i want to limit it to page 1-5, can i do that?

Thom Parker
Inspiring
October 22, 2022

Thank you for the script but my work flow requires limiting script to page rank....how can i do that(let's say page 5-10)?


In Acrobat JavaScript, field objects have a page property. If there is only one field on in the document with a particular field name, this property is an integer indicating the 0 based page number.  However, it's not that simple because fields with the same name can be on many different pages. Also some fields naturally have more instances, such as radio buttons. In these cases the field page property  is an array of page numbers. That's all you need to know to figure out what pages a particular field is on. 

 

This code returns true if if a field is in a page range. Specifically on page 1 to 5.

 

 

var nPgMin = 0, nPgMax = 4;
var oFld = this.getField("xxx");
var aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
var bOnPage = aPgs.some(a=> a>=nPgMin && a<=nPgMax);

 

 

It can easily be integrated in the code provided by Try67 for testing all fields on the PDF.

 

You might also be interested in the answer I provided here:

https://community.adobe.com/t5/acrobat-discussions/reset-only-page-1-with-a-poppup/m-p/13286650#M384005

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often