Redaction
Permanently remove text, images and annotations from PDFs in the browser by area, by text, by regular expression or by pattern with NexPDF for the web.
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. Because the engine runs in the page, the unredacted document never leaves the device.
Redact an area
doc.redact(0, [72, 600, 300, 620]); // page, rect; black box
doc.redact(1, [72, 500, 300, 520], true); // white box
const redacted = doc.toBlob();Redact every match of a text, an expression or a pattern
doc.raw.redactMatches(query, mode, fillWhite) finds and redacts every match in the document and
returns the number of areas redacted. fillWhite is 0 or 1.
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 |
let n = doc.raw.redactMatches('CONFIDENTIAL', 0, 0);
n += doc.raw.redactMatches(String.raw`\b\d{3}-\d{2}-\d{4}\b`, 1, 0);
n += doc.raw.redactMatches('email', 2, 0);
console.log(`${n} areas redacted`);Review before redacting
Use search to show the matches to a reviewer first, for example drawn over the page or 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, for example with
doc.raw.clone().