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


NSURL *url = [NSURL fileURLWithPath:pdfPath];
CPDFDocument *document = [[[CPDFDocument alloc] initWithURL:url] autorelease];
CPDFPage *page = [document pageAtIndex:0];

CPDFRedactAnnotation *redact = [[[CPDFRedactAnnotation alloc] initWithDocument:document] autorelease];
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];


- Applying Redactions Programmatically


[redact applyRedaction];