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 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