Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redact or Black out Text in Image within PDF using C#
// Redact Text in PDF and Text in Image like scanned document using Java
RedactorSettings settings = new RedactorSettings(new AsposeCloudOcrConnector());
try (Redactor redactor = new Redactor("path/document.pdf", new LoadOptions(), settings))
{
ReplacementOptions marker = new ReplacementOptions(java.awt.Color.BLACK);
Redaction redactions[] = new Redaction[] {
new RegexRedaction("(?<=Dear\\s)([^,]+)", marker), // cardholder name
new RegexRedaction("\\d{2}/\\d{2}", marker), // valid thru
new RegexRedaction("\\d{4}", marker) // card number parts
};
RedactorChangeLog result = redactor.apply(redactions);
if (result.getStatus() != RedactionStatus.Failed)
{
redactor.save(new SaveOptions(false, "redacted"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment