Copy link to clipboard
Copied
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.
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",
...
Copy link to clipboard
Copied
Why does you destroy all annotations? A annotations type "Rectangle" doesn't exists.
Copy link to clipboard
Copied
Hi Bernd. The reason is that once it has created the redaction box i no longer need the rectangle annotation.
Copy link to clipboard
Copied
Info: A annotations type "Rectangle" doesn't exists.
Copy link to clipboard
Copied
So it should be "Square"?
I know very little about coding, but is this basically what i need to do
1. Find "Square" annotation
2. Find quad for anotation
3. add redaction box using the quad info found in step 2
4. apply
Copy link to clipboard
Copied
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,
});
Copy link to clipboard
Copied
Put the calculation of qd in the loop.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Put it before addAnnot.
Copy link to clipboard
Copied
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,
});
Copy link to clipboard
Copied
Is there anyway to make the redaction boxes smaller?
Copy link to clipboard
Copied
Yes, you can do that by changing the quads for the redaction annotation to make a smaller rectangle.