Skip to end of metadata
Go to start of metadata
Contents Summary
 

The code in below examples uses some methods defined in the Common Utilities.

Exact Phrase Redaction 

Using GroupDocs.Redaction API, you can perform exact phrase redaction by replacing the exact phrase "John Doe" with "[personal]" or any exemption code.

The Recipe

  • Load Document using Redactor.Load(@"C:\sample.pdf")

  • Perform exact phrase redaction using Document.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")))

  • Save document using Document.Save() 

The Code

Case-Sensitive Exact Phrase Redaction 

GroupDocs.Redaction API also allows performing case-sensitive exact phrase redaction. By default, search for the exact phrase is case insensitive. For a case-sensitive redaction, you can set the corresponding constructor parameter to ture.

The Recipe

  • Load Document using Redactor.Load(@"C:\sample.pdf")

  • Perform case-sentitive exact phrase redaction using Document.RedactWith(new ExactPhraseRedaction("John Doe",  true /*isCaseSensitive*/ ,new ReplacementOptions("[personal]")))

  • Save document using Document.Save()

The Code

Color Redacted Text 

Using GroupDocs.Redaction API, you can insert a color box over the redacted text instead of replacement string. The redaction will erase matched text and put a rectangle of the specified color in place of redacted text.

The Recipe

  • Load Document using Redactor.Load(@"C:\sample.pdf")

  • Color redacted text using Document.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Black)))

  • Save document using Document.Save()

The Code

Regular Expression Redaction

Using GroupDocs.Redaction API, you can also perform regular expression redaction. Behind the scenes, exact phrase redaction works through regular expressions, which is the baseline approach for redaction. For example, we redact out any text, matching "2 digits, space or nothing, 2 digits, again space and 6 digits" with a blue color box.

The Recipe

  • Load Document using Redactor.Load(@"C:\sample.pdf")

  • Color redacted text using Document.RedactWith(new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions(System.Drawing.Color.Blue)))

  • Save document in it's original format using Document.(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false })

The Code

Labels
  • No labels