Skip to main content
Inspiring
Dec 8, 2020 4:34 AM UTC
Answered

Converting a rectangle annotation to a redaction

Hi. I have a simple javascript that will convert highlight annotations to redactions. That works well. However it would be better if I could also use the rectangle (or other shape) annotation. But i cant get the script to work. It just deletes the annotion, I am assuming because I need to somehow specify that the redaction box be the same size / location as the rectangle. Is anyone able to help?

 

Here is what i have so far:

 

var annots = this.getAnnots();
for (var i=annots.length-1; i>=0; i--) {
       if (annots[i].type == "Rectangle") {
           this.addAnnot( {
           page: annots[i].page,
           type: "Redact",
           rect: annots[i].rect,
           overlayText: "REDACTED",
           alignment: 1,
           alignment: true,
           fillColor: color.black,
           textColor: color.white,
           textSize: 0,
           });
     }
     annots[i].destroy();
}

this.applyRedactions ({
bKeepMarks: false,
bShowConfirmation: false,
})

 

 

P.S. the reason for this is that not all people in my office have Adobe Pro. This means that the solicitors with Reader can mark what they want me to redact and I can redact it faster than manually going through.

This topic is closed to new replies. Start a new post to keep the conversation going.
leroy0101Correct answer
Inspiring
Dec 13, 2020 10:49 PM UTC

Ok thanks to Bernd I have managed to get this to work. So for everyone else who might find this helpfull here is hte code

var annots = this.getAnnots();
for (var i=annots.length-1; i>=0; i--) {
    if (annots[i].type == "Square") {
    var rct = annots[i].rect;
    var left = rct[0];
    var right = rct[2];
    var top = rct[3];
    var bot = rct[1];
    var qd = [ [left, top, right, top, left, bot, right, bot] ];        
    this.addAnnot( {
        page: annots[i].page,
        type: "Redact",
        quads: qd,
        overlayText: "REDACTED", //THIS IS THE REDACTION TEXT
        alignment: 1,            // "0" = LEFT, "1" = CENTRE, "2" = RIGHT
        fillColor: color.black,  //THIS CHANGES THE FILL COLOUR
        textColor: color.white,  //THIS CHANGES THE FONT COLOUR
        textSize: 0,             //FONT SIZE, '0' will adjust the size to fit each box, otherwise you can use a specific font size
        });
    }
}

this.applyRedactions ({
bKeepMarks: false,
bShowConfirmation: false,
});

 

11 replies

leroy0101AuthorCorrect answer
Inspiring
Dec 13, 2020 10:49 PM UTC

Ok thanks to Bernd I have managed to get this to work. So for everyone else who might find this helpfull here is hte code

var annots = this.getAnnots();
for (var i=annots.length-1; i>=0; i--) {
    if (annots[i].type == "Square") {
    var rct = annots[i].rect;
    var left = rct[0];
    var right = rct[2];
    var top = rct[3];
    var bot = rct[1];
    var qd = [ [left, top, right, top, left, bot, right, bot] ];        
    this.addAnnot( {
        page: annots[i].page,
        type: "Redact",
        quads: qd,
        overlayText: "REDACTED", //THIS IS THE REDACTION TEXT
        alignment: 1,            // "0" = LEFT, "1" = CENTRE, "2" = RIGHT
        fillColor: color.black,  //THIS CHANGES THE FILL COLOUR
        textColor: color.white,  //THIS CHANGES THE FONT COLOUR
        textSize: 0,             //FONT SIZE, '0' will adjust the size to fit each box, otherwise you can use a specific font size
        });
    }
}

this.applyRedactions ({
bKeepMarks: false,
bShowConfirmation: false,
});

 

Translate
Participant
Oct 23, 2023 8:13 PM UTC

Is there anyway to make the redaction boxes smaller?

Translate
Thom Parker
Community Expert
Community Expert
Oct 23, 2023 10:46 PM UTC

Yes, you can do that by changing the quads for the redaction annotation to make a smaller rectangle. 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
leroy0101Author
Inspiring
Dec 9, 2020 2:00 AM UTC

UPDATE - So i have managed to get the code to kind of work, but im not sure how to to get this code to loop through every annotation box in the  PDF. 

var annots = this.getAnnots();
var rct = getAnnots(this.pageNum)[0].rect;
var left = rct[0];
var right = rct[2];
var top = rct[3];
var bot = rct[1];
var qd = [ [left, top, right, top, left, bot, right, bot] ];
for (var i=annots.length-1; i>=0; i--) {
    if (annots[i].type == "Square") {
        this.addAnnot( {
        page: annots[i].page,
        type: "Redact",
        quads: qd,
        overlayText: "REDACTED",
        alignment: true,
        fillColor: color.black,
        textColor: color.white,
        textSize: 0,
        });
    }
}

this.applyRedactions ({
bKeepMarks: false,
bShowConfirmation: false,
});

Translate
Bernd Alheit
Community Expert
Community Expert
Dec 9, 2020 8:35 AM UTC

Put the calculation of qd in the loop.

Translate
leroy0101Author
Inspiring
Dec 10, 2020 9:17 PM UTC

Hi Bernd, can you please point in the the direction of how to do this. I dont have any coding experience, but if you could tell me a bit more specifically where it needs to go in the code, then maybe i can figure the rest out on my own. It would be a good learning experience. Thanks. 

Translate
Bernd Alheit
Community Expert
Community Expert
Dec 8, 2020 9:14 AM UTC

Why does you destroy all annotations? A annotations type "Rectangle" doesn't exists.

Translate
leroy0101Author
Inspiring
Dec 8, 2020 7:23 PM UTC

Hi Bernd. The reason is that once it has created the redaction box i no longer need the rectangle annotation. 

Translate
Bernd Alheit
Community Expert
Community Expert
Dec 8, 2020 7:40 PM UTC

Info: A annotations type "Rectangle" doesn't exists.

Translate