How to Redact in Word Processing Documents Using C# or Java Programming

How to redact in Word – The redacted meaning is extensively searched over the internet now a days . C# or Java programming developers might want to upgrade their editing apps by adding a feature to redact in Word, redact PDF or they might need some redacted text in many kinds of documents. If you are a developer and want to enable text redaction in your app , the stuff below is definitely for you.

Why redacted information in the documents is remarkable

how to redact in word

A redacted document contain touchy data is vital to each person, extending from a sole owner to government offices. Nobody likes it when their private or secret data fall into some inappropriate hands. This routine is likewise regular among legal counselors. Nevertheless, how to redact in Word documents is not so simple. The vast majority have committed errors previously in this regard. Utilizing incorrect strategies to redact your data will prompt the spillage of your private information. Many people are using wrong techniques like erasing, changing the text color to white or utilizing obsolete apps to make redacted text in their documents.

The following section shows that how Java orC# Programming developers can do it using their coding editors.

Text redaction in your word documents using C# or Java APIs

Using GroupDocs.Redaction premise APIs you can simply write a program to redact the information in variety of documents or you might want to add text redaction feature in your editing apps. If you are going to make a
redaction software, you might be interested in metdata redactions, image redactions, annotation redactions,or spreadsheet redactions.

Lets learn how simply the C# or Java Programming developers can write the code to redact in Word documents

The GroupDocs.Redaction APIs enable you the text redaction in two ways”

  1. Exact phrase redaction
  2. Using regular expression

Using exact phrase redaction

The example below shows textual redaction by replacing personal exact phrase “John Doe” with “[personal]”:

using (Redactor redactor = new Redactor(@"sample.docx"))
{
  redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
  redactor.Save();
}

Java code will look like this:

final Redactor redactor = new Redactor("sample.docx");
try
{
    redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
    redactor.save();
}
finally { redactor.close(); }

For a case sensitive redaction, you can pass a constructor parameter and corresponding public property like:

using (Redactor redactor = new Redactor(@"sample.docx"))
{
  redactor.Apply(new ExactPhraseRedaction("John Doe", true /*isCaseSensitive*/, new ReplacementOptions("[personal]")));
  redactor.Save();
}

Java code will look like this:

final Redactor redactor = new Redactor("sample.docx");
try
{
    redactor.apply(new ExactPhraseRedaction("John Doe", true /*isCaseSensitive*/, new ReplacementOptions("[personal]")));
    redactor.save();
}
finally { redactor.close(); }

If you need a color box over the redacted text, you can use color instead of replacement string. The redaction will erase matched text and put a rectangle of the specified color in place of redacted text:

using (Redactor redactor = new Redactor(@"sample.docx"))
{
  redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Black)));
  redactor.Save();
}

Java code will look like this:

final Redactor redactor = new Redactor("sample.docx");
try
{
    redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(java.awt.Color.RED)));
    redactor.save();
}
finally { redactor.close(); }

Using regular expression

The example below shows the redact out any text, matching “2 digits, space or nothing, 2 digits, again space and 6 digits” with a blue color box:

using (Redactor redactor = new Redactor(@"sample.docx"))
{
  redactor.Apply(new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions(System.Drawing.Color.Blue)));
  redactor.Save();
}

Java code will look like this:

final Redactor redactor = new Redactor("sample.docx");
try
{
    redactor.apply(new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions(java.awt.Color.BLUE)));
    SaveOptions saveOptions = new SaveOptions();
    saveOptions.setAddSuffix(true);
    saveOptions.setRasterizeToPDF(false);
    redactor.save(saveOptions);
}
finally { redactor.close(); }

The complete ready to run code sample is available on GitHub. You can explore API references for both Java and .NET versions. The GroupDocs also offers a one month free trial for both Java and .NET APIs. Please visit here to get the trial license.