Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active September 25, 2021 05:33
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/f7e22d6719c21108d804756913b2ca3f to your computer and use it in GitHub Desktop.
Save GroupDocsGists/f7e22d6719c21108d804756913b2ca3f 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 C#
var settings = new RedactorSettings(new AsposeOCRStandaloneConnector(@"LICENSE_PATH"));
using (var redactor = new Redactor(@"path/document.pdf", new LoadOptions(), settings))
{
var marker = new ReplacementOptions(Color.Black);
var redactions = new Redaction[] {
new RegexRedaction(@"(?<=Dear\s+)([^,]+)", marker), // Card Holder Name
new RegexRedaction(@"\d{2}/\d{2}", marker), // Valid Thru
new RegexRedaction(@"\d{4}", marker) // Card Number
};
var result = redactor.Apply(redactions);
if (result.Status != RedactionStatus.Failed)
{
redactor.Save(new SaveOptions(false, "OnPremise"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment