Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created October 7, 2021 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/15992c7e04f496134f00ffb297514c75 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/15992c7e04f496134f00ffb297514c75 to your computer and use it in GitHub Desktop.
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