Android
ComPDFKit PDF SDK
Guides

Redaction

 

Redaction is the process of removing images, text, and vector graphics from a PDF page. This not only involves obscuring the content, but also removing the data in the document within the specified area.

 

Redaction typically involves removing sensitive content within documents for safe distribution to courts, patent and government institutions, the media, customers, vendors, or any other audience with restricted access to the content. Redaction is a two-step process.

 

- First, redaction annotations have to be created in the areas that should be redacted. This step won’t remove any content from the document yet; it just marks regions for redaction.

 

- Second, to actually remove the content, the redaction annotations need to be applied. In this step, the page content within the region of the redaction annotations is irreversibly removed.

 

This means that the actual removal of content happens only after redaction annotations are applied to the document. Before applying, the redaction annotations can be edited and removed the same as any other annotations.

 

Redacting PDFs programmatically:

 

- Creating Redactions Programmatically

 

You can create redactions programmatically via CPDFRedactAnnotation. Use the setQuadRects or setRect property to set the areas that should be covered by the redaction annotation.

 

You also have a few customization options for what a redaction should look like, both in its marked state, which is when the redaction has been created but not yet applied, and in its redacted state, which is when the redaction has been applied. It is impossible to change the appearance once a redaction has been applied, since the redaction annotation will be removed from the document in the process of applying the redaction.

This is how to create a redaction annotation that covers the specified region on the first page of a document:

 

CPDFRedactAnnotation redactAnnotation = (CPDFRedactAnnotation) page.addAnnot(CPDFAnnotation.Type.REDACT);
RectF pageSize = readerView.getPageNoZoomSize(pageNumber);
RectF insertRect = new RectF(0,0,100,100);
//coordinate conversion
insertRect = document.pageAtIndex(pageNumber).convertRectToPage(readerView.isCropMode(),pageSize.width(),pageSize.height(),insertRect);

redactAnnotation.setRect(insertRect);
CPDFTextAttribute textAttribute = new CPDFTextAttribute(CPDFTextAttribute.FontNameHelper.obtainFontName(CPDFTextAttribute.FontNameHelper.FontType.Helvetica,false,false),14,Color.YELLOW);
redactAnnotation.setOverLayText("REDACT");
redactAnnotation.setFillColor(Color.BLACK);

 

- Applying Redactions Programmatically

 

redactAnnotation.applyRedaction();
readerView.reloadPages();