Redaction
Permanently remove text, images and annotations from PDFs by area, by text, by regular expression or by pattern with NexPDF for Android.
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 = true. Save the document afterwards. The reader has a
redaction mode for the user.
Redact an area
import com.nexdevit.nexpdf.NexPdfDocument
import com.nexdevit.nexpdf.NexPdfJni
NexPdfDocument.openBytes(bytes).use { doc ->
// handle, page, llx, lly, urx, ury, fillWhite
NexPdfJni.applyRedaction(doc.handle(), 0, 72.0, 600.0, 300.0, 620.0, false)
val redacted = doc.saveBytes()
}Redact every match of a text, an expression or a pattern
NexPdfJni.redactMatches(handle, query, mode, fillWhite) finds and redacts every match in the
document and returns the number of areas redacted, or -1 on error.
mode | query is |
|---|---|
0 | Plain text |
1 | A regular expression |
2 | A pattern id: email, phone, credit-card, iban, pt-nif, us-ssn, ipv4, url, date |
val h = doc.handle()
var n = NexPdfJni.redactMatches(h, "CONFIDENTIAL", 0, false)
n += NexPdfJni.redactMatches(h, """\b\d{3}-\d{2}-\d{4}\b""", 1, false)
n += NexPdfJni.redactMatches(h, "email", 2, false)
Log.i("NexPDF", "$n areas redacted")
val redacted = doc.saveBytes()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.