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

Marking and Redacting PDF

New Here ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Hello everyone,

 

I  mark documents for redaction by using the drawing tool to place a rectangle around sensitive data. I then use javascript to place redaction boxes within the rectangles. However, I would like to apply the redactions without deleting the rectangles. Can you help me accomplish this task?

 

Additionally, I prefer to mark documents for redaction using brackets like these "[ ]" , or using a partiallty-completed square/rectangle (only the corners, or the top left and bottom right corner). Is there a drawing tool, or a javascript function that can produce such annotations? I hope to use these annotations instead of the rectangle. 

 

Here is the code I am using to find rectangle annotations and redact. It is very similar to the code provided here: https://acrobatusers.com/tutorials/auto_redaction_with_javascript/

 

// Get the active document

var doc = event.target;

 

// Get all the rectangle shapes in the document

var rectangles = doc.getAnnots({type: "Rect"});

 

// Loop through each rectangle shape

for (var i = 0; i < rectangles.length; i++) {

    var rectangle = rectangles[i];

 

    // Get the rectangle's coordinates

    var rct = getAnnots(this.pageNum)[i].rect;

    var left = rct[0];

    var right = rct[2];

    var top = rct[3];

    var bot = rct[1];

    qd = [ [left, top, right, top, left, bot, right, bot] ];

    qd.toSource();

 

    // Create a new redaction annotation within the rectangle's bounds

    var redaction = this.addAnnot({

        type: "Redact",

        page: rectangle.page,

        quads: qd,

        repeat:true

    });

}

 

Thank you in advance for your help. Much Appreciated

 

TOPICS
Edit and convert PDFs , General troubleshooting , How to , JavaScript

Views

425

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 ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

There are a number of issues with this code, but it does not explicitly delete the rectangle annotation.  The rectangle is removed when the redaction is applied, because it is in the same location. If you want to maintain the rectangles, then they will need to either be recreated after redactions are applied, or moved out of the way before applying redaction, then moved back after.  Recreating them is much simpler. 

 

There is no square bracket annotation. One could be created with a plug-in, but otherwise you have what you get with Acrobat. But, why mark redactions with the rectangle at all, why not just use the redaction tool?  I see no advantage to your methodology. 

 

Now, lets cover some of the issues with your code. 

1.  this line "var doc = event.target;" only makes sense in the context of an application level event. Was the intention to use this code in an automation script? If so, then the "doc" variable needs to be used everywhere the document object is necessary. And it is not. The code is very inconsistent. It is obviously being run from a document context, since the document object is missing in one place, and the keyword "this" is used in another. 

You can read about automation scripting here:

https://www.pdfscripting.com/public/Automating-Acrobat.cfm

 

2.  doc.getAnnots({type: "Rect"});

There is no "type" argument for the "getAnnots" function.  This call gets all annotations on the PDF, regardless of type. 

 

3.  var rct = getAnnots(this.pageNum)[i].rect;

This is a non-sensical line of code. The annotation has already been gotten and it's inside a loop that is iterating over the annotations. Also "this.pageNum", refers to the current page being shown to the user, not the page the annotation is on.  And further "this" is a context dependent keyword. It is not necessarily refer to the current document. This is where the "doc" variable you've defined earlier needs to be used. 

Just use the existing annot like this

 var rct = rectangles[i].rect;

 

4. " qd.toSource();"

This code is for testing in the console window. It does not belong in a working script. 

 

 

 

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
New Here ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

Thanks so much. this is very helpful. 

 

I use rectangles instead of simply using the redact tool because its a little easier to mark areas with more precision, and the shape can be easily customized, though customization options are limited.  Also, I was not sure how to preserve the redaction mark after redaction . When processing Pdf's, I have to identify sensitive info using brackest/rectangles, then print a version with these brackets/rectangles, then make a redacted version of a ducment with the brackets intact, and the images/text inside the brackets removed. For example, PDF 1 would look like this: "[blah blah]", and PDF 2, like this "[      ]".

 

One additional question: by "recreating," do you mean exporting them to an FDF file, then importing them after the redacting is done?

 

As for the coding errors, thanks for the corrections. I don't really code, so the code provided is cobbled together from trial and error. 

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 ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

LATEST

If you want the redacted text replaced with empty brackets, then specify the brackets as the replacement text. 

 

But to recreate the rectangle you'd need to save an array of the properties needed to recreate them. This could be maintained in a global object. 

 

JavaScript is a pretty easy language to learn (for computer languages). It's well worth the effort to spend some time learning about the core language. 

 

 

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