Skip to content
Guides

Redact PDFs

The steps to redact PDFs are as follows:

  1. Create Redaction Annotations: A user applies to redact annotations that specify the pieces or regions of content that should be removed. This step marks the regions where redaction changes will be applied. These redaction annotations can be set, moved, or deleted before applying redaction changes, without removing content from the document.
  2. Apply Redaction Changes: After marking the areas for complete content removal, apply redaction changes. The content within the regions of the redaction annotations will be irreversibly deleted.

Through these two steps, you can thoroughly remove sensitive data from the document.

Create Redaction Annotations

You can use the CPDFRedactAnnotation class to create redaction annotations. Utilize the setRect methods to define the areas that should be covered by the redaction annotations.

In addition, the appearance of the ciphertext can be customized at this stage. Note that once redaction annotations have been applied, their appearance cannot be changed. This is because the redaction annotations will become non-editable, non-modifiable, static content instead of an interactive ciphertext annotation after it has been applied.

This sample shows how to create a redaction annotation:

java
CPDFDocument document = new CPDFDocument();
document.open(pdfPath);
CPDFPage pdfPage = document.pageAtIndex(0);
CPDFRedactAnnotation redactAnnotation = (CPDFRedactAnnotation) pdfPage.addAnnot(CPDFAnnotation.Type.REDACT,document);
RectF insertRect = new RectF(0, 0, 100, 100);
redactAnnotation.setRect(insertRect);
CPDFTextAttribute textAttribute = new CPDFTextAttribute("Helvetica", 14, Color.YELLOW.getRGB());
redactAnnotation.setTextDa(textAttribute);
redactAnnotation.setFillColor(Color.RED.getRGB());
redactAnnotation.setOverLayText("REDACTED");
redactAnnotation.updateAp();
redactAnnotation.applyRedaction();

Apply Redaction Changes

ComPDFKit SDK ensures that if text, images, or vector graphics are included in the region marked by a redaction annotation, the corresponding image or path data in that portion will be completely removed and cannot be restored.

This sample shows how to apply redaction changes:

java
redactAnnotation.applyRedactions();