Skip to main content
Participating Frequently
June 6, 2025
Answered

Count Unapplied Redaction Boxes?

  • June 6, 2025
  • 1 reply
  • 543 views

I know I can't count the number of redactions in a pdf after they've been applied. I tried the suggested java script from try67 given to kimberlyt8816 on Mar 31, 2017 with both applied and unapplied, saved redaction boxes and it returns "0" redaction annotations.

Is there a way to count saved, UNapplied redaction boxes in a pdf document?

Correct answer PDF Automation Station

That script counts the number of pages that contain at least 1 redaction annotation, not the total number of redaction annotations - with one correction:

this line

 if (annots.type=="Redact") {

should read

 if (annots[i].type=="Redact") {

1 reply

PDF Automation Station
Community Expert
Community Expert
June 6, 2025

If you say you used a script and it doesn't work you should post it.  Yes there is a way.  Run this script:

var count=0;
var anot=this.getAnnots();
for(var i=0;i<anot.length;i++)
{
if(anot[i].type=="Redact")
{count+=1}
}


Then call the count variable.

ChrisOJRCAuthor
Participating Frequently
June 6, 2025

Thanks, that works, although it returns a number that is one fewer than the actual number of unapplied redaction boxes. But that's no biggie. 

What did you mean by "Then call the count variable?"
The JS suggested by try67 (which apparently didn't work for kimberlyt8816) was:

this.syncAnnotScan();

 

var counter = 0;

 

for (var p=0; p<this.numPages; p++) {

 

   var annots = this.getAnnots({nPage: p});

 

   if (annots==null || annots.length==0) continue;

 

   for (var i in annots) {

 

       if (annots.type=="Redact") {

 

           counter++;

 

           break;

 

       }

 

   }

 

}

PDF Automation Station
Community Expert
Community Expert
June 6, 2025

If the script is in a field, you would add the line

event.value=count;

If you are running the script in the console, just add the word count to the end of the script.  I made a slight correction to my script so that it returns the correct number without having to call the variable.