Skip to Content
NexPDF

Redaction

Permanently remove text, images and annotations from PDFs by area, by text, by regular expression or by pattern with NexPDF for iOS (Swift).

English

License module

Redaction needs the redaction module (Business tier and above).

Redaction in NexPDF is destructive: the text, images and annotations under the area are removed from the file, not just covered, and an opaque box is painted over it: black, or white with fillWhite: 1. Save the document afterwards. The reader has a redaction mode for the user.

Redact an area

import NexPdf

let doc = try NexPdfDocument.open(url: url)
try doc.applyRedaction(pageIndex: 0, llx: 72, lly: 600, urx: 300, ury: 620, fillWhite: 0)
try doc.write(to: redactedURL)

Redact every match of a text, an expression or a pattern

redactMatches(query:mode:fillWhite:) finds and redacts every match in the document and returns the number of areas redacted.

modequery is
0Plain text
1A regular expression
2A pattern id: email, phone, credit-card, iban, pt-nif, us-ssn, ipv4, url, date
var n = try doc.redactMatches(query: "CONFIDENTIAL", mode: 0, fillWhite: 0)
n += try doc.redactMatches(query: #"\b\d{3}-\d{2}-\d{4}\b"#, mode: 1, fillWhite: 0)
n += try doc.redactMatches(query: "email", mode: 2, fillWhite: 0)
print("\(n) areas redacted")
try doc.write(to: redactedURL)

Review before redacting

Use search to show the matches to a reviewer first, for example as highlight annotations, and apply the redaction once they are approved.

Redaction cannot be undone in the saved file. Keep the original if you may need it.

On this page