Skip to content
Guides

Redact PDFs

Redact content from a PDF document involves two steps:

  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 quadrilateralPoints or bounds 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:

swift
let url = URL(fileURLWithPath: "File Path")
let document = CPDFDocument(url: url)

let page = document?.page(at: 0)
let redact = CPDFRedactAnnotation(document: document)
redact?.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
redact?.setOverlayText("REDACTED")
redact?.setFont(UIFont.systemFont(ofSize: 12))
redact?.setFontColor(UIColor.red)
redact?.setAlignment(.left)
redact?.setInteriorColor(.black)
redact?.setBorderColor(.yellow)
page?.addAnnotation(redact)
objective-c
NSURL *url = [NSURL fileURLWithPath:pdfPath];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
CPDFPage *page = [document pageAtIndex:0];

CPDFRedactAnnotation *redact = [[CPDFRedactAnnotation alloc] initWithDocument:document];
redact.bounds = CGRectMake(0, 0, 50, 50);
redact.overlayText = @"REDACTED";
redact.font = [UIFont systemFontOfSize:12];
redact.fontColor = [UIColor redColor];
redact.alignment = NSTextAlignmentLeft;
redact.interiorColor = [UIColor blackColor];
redact.borderColor = [UIColor yellowColor];
[page addAnnotation:redact];

Apply Redaction Changes

The 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:

swift
redact?.applyRedaction()
objective-c
[redact applyRedaction];