Converting Adobe annotations to redactions using java

327 views Asked by At

Firstly I am unfortunately not a coder. So i suspect that some of this is probably glaring obvious to you all. I provide legal support to a team of lawyers. They often need PDFs redacted and they usually highlight what they need redacted and I use Adobe's redact tool. I have a snippet of code that will convert highlights to redactions but it only works on OCR'd text. What I would like to be able to do is convert the rectangle annotation to a redaction.

This is what I have so far:

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,
});

It works for the first rectangle annoation, but doesnt loop for every rectangle annotation. I know that i need to add this part:

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] ];

into the For statement, but I cant figure out how. Any help would be appreciated

1

There are 1 answers

0
Leroy P On

Ok thanks to Bernd (from the adobe forum) I have managed to get this to work. So for everyone else who might find this helpful here is the 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,
});