Last active
September 25, 2021 05:33
-
-
Save GroupDocsGists/f7e22d6719c21108d804756913b2ca3f to your computer and use it in GitHub Desktop.
Redact or Black out Text in Image within PDF using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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