• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Converting a rectangle annotation to a redaction

Community Beginner ,
Dec 07, 2020 Dec 07, 2020

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.

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Dec 13, 2020 Dec 13, 2020

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",
...

Votes

Translate

Translate
Community Expert ,
Dec 08, 2020 Dec 08, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2020 Dec 08, 2020

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2020 Dec 08, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2020 Dec 08, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2020 Dec 08, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

Put the calculation of qd in the loop.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 10, 2020 Dec 10, 2020

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2020 Dec 11, 2020

Copy link to clipboard

Copied

Put it before addAnnot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 13, 2020 Dec 13, 2020

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2023 Oct 23, 2023

Copy link to clipboard

Copied

Is there anyway to make the redaction boxes smaller?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2023 Oct 23, 2023

Copy link to clipboard

Copied

LATEST

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

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines