English

Redact PDF, Word, Excel, PowerPoint, and image files in .NET

Build custom redaction apps in .NET to securely redact PDF files, Word documents, Excel spreadsheets, PowerPoint presentations, PNG, JPG, GIF, and TIFF images using the .NET redaction API. You can redact annotations, metadata, and text to effortlessly protect sensitive information and improve file security and privacy.

Try our APIs for FreeGet Temporary License

Intelligent Document Redaction for Enhanced Security

The process of obscuring or removing confidential data from a file is known as redaction. The redacted data is usually considered sensitive, private, or classified. Improving file security and maintaining the privacy of the information contained within data files are two of the core purposes of redaction. Document redaction could also help secure sensitive personal data such as bank accounts or social security numbers, passwords, addresses, and much more.

Considering the ever-increasing concerns about data privacy, redaction tools, and software have gained much importance. Such tools allow users to electronically redact or hide different types of user data from their multi-format documents. If you are also looking for a feature-rich document redaction tool, look no further than GroupDocs.Redaction for .NET. This document redaction API packs a set of very useful, easy-to-use features for redacting text, annotation, and metadata from PDF, DOCX, XLSX, PPTX, ODT, RTF, PNG, JPG, GIF, and TIFF files.

Getting Started

Before you start redacting your documents using GroupDocs.Redaction for .NET, please ensure having installed the correct API version and any other prerequisites. You have a few options for installing the .NET redaction API such as using NuGet or obtaining the MSI installer from the downloads section. You can also install it via the Package Manager Console:

PM> Install-Package GroupDocs.Redaction

For further help and information, please check this guide.

Document redaction use cases

After successfully setting up GroupDocs.Redaction for .NET on your system, let’s now check some use cases of the document redaction API for classified information redaction from your documents.

Text Redaction: Exact Phrase and Regular Expression Methods in .NET

Redacting text is one of the commonly used methods for masking sensitive information in a document. You can use text redaction to protect personal or financial details mentioned in a document (in textual form) by simply concealing or deleting the text that contains such confidential data. Text redaction provides a simple yet effective way of safeguarding your important data. GroupDocs.Redaction for .NET allows you to the exact phrase or a regular expression to redact specified text from your PDF and Word documents, Excel spreadsheets, and PowerPoint presentations.

Text Redaction: Exact Phrase and Regular Expression Methods in .NET

Use the exact phrase to redact text in .NET

If you are looking to replace text containing important personal details from a file with custom text using the exact phrase, please use the C# code given below. This code will replace the name 'John Doe' with the specified text thus redacting the name of the person from the document:

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

For applying a rectangular black-colored box over the redacted text instead of a replacement string, please use the following code snippet:

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

Using a regular expression for redacting text

You can also use a regular expression for redacting. The below-given C# code will redact text which matches the regular expression sequence of 'two digits, space, two digits, space again and six digits' (example: 12 34 567890) while also inserting a blue-colored rectangular box in place of the redacted text:

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();
}

Mastering Annotation Redaction in Your .NET Redaction Applications

Annotations added to a document may contain information that could be classified as sensitive. Therefore, you may want to protect the content of the document annotations. GroupDocs.Redaction for .NET lets you redact the annotation text or remove the annotation altogether.

Mastering Annotation Redaction in Your .NET Redaction Applications

Build C#, .NET redaction apps to obscure and delete annotation contents

Please utilize the following C# code to redact the contents of annotations from your .NET documents of PDF, Word, Excel, PowerPoint, RTF, and many other formats:

using (Redactor redactor = new Redactor(@"C:\sample.pdf"))
{
//Redacting all occurrences of ‘John’ from document annotations
redactor.Apply(new AnnotationRedaction("(?im:john)", "[redacted]"));
   redactor.Save()
}    

Remove annotations programmatically from your multi-format .NET files

Just like redacting what’s contained within the annotations, you can completely remove the annotations if needed. Please use the code given below to achieve this:

using (Redactor redactor = new Redactor(@"C:\sample.docx"))
{
   //Deleting comments or annotations containing ‘use’, ‘show’, ‘describe’
   redactor.Apply(new DeleteAnnotationRedaction("(?im:(use|show|describe))"));

   redactor.Save()
} 

Effortlessly Redact Sensitive Information from PNG, JPG, GIF, or TIFF Images

When working with images, you may encounter a situation where you must remove or redact sensitive information from them. This could be anything from a social security number to the face of a person. Redaction for .NET can work as the perfect image redaction tool for you to sanitize PNG, GIF, TIFF, and JPG images by redacting specific areas in image files, searching and redacting text in an image, or redacting embedded images in .NET.

Effortlessly Redact Sensitive Information from PNG, JPG, GIF, or TIFF Images

Redact a specified area inside an image file

To redact a certain area in an image using the .NET redaction API, please use the C# code shown below. While we are using a JPG file in this sample code for image redaction, you may use any of the other supported image formats such as PNG, GIF, TIFF, or BMP:

    using (Redactor redactor = new Redactor("D:\\sample.jpg"))
    {
       System.Drawing.Point samplePoint = new System.Drawing.Point(516, 311);
       System.Drawing.Size sampleSize = new System.Drawing.Size(170, 35);
       RedactorChangeLog result = redactor.Apply(new ImageAreaRedaction(samplePoint,
                    new RegionReplacementOptions(System.Drawing.Color.Blue, sampleSize)));
       if (result.Status != RedactionStatus.Failed)
       {
          redactor.Save();
       };
    }     

Apply embedded image redaction in .NET

Along with the usual image redaction, you can also redact images embedded in a document using the .NET redaction API. To redact images embedded with a Microsoft Word file, please use the following code snippet:

    using (Redactor redactor = new Redactor("D:\\sample.docx"))
    {
       System.Drawing.Point samplePoint = new System.Drawing.Point(516, 311);
       System.Drawing.Size sampleSize = new System.Drawing.Size(170, 35);
       RedactorChangeLog result = redactor.Apply(new ImageAreaRedaction(samplePoint,
                    new RegionReplacementOptions(System.Drawing.Color.Blue, sampleSize)));
       if (result.Status != RedactionStatus.Failed)
       {
          redactor.Save();
       };
    }     

Different Ways to Save a Redacted File with .NET Document Redaction API

Redacting data in documents and images not only enhances content safety but helps with data integrity as well. Redaction is also a way of protecting your sensitive data from getting misused. Now that you have learned all about redacting classified information from different types of files, let’s review saving redacted files using GroupDocs.Redaction for .NET. This document redaction API for .NET allows saving the redacted file in its original format, overwriting the original file, and saving it as a rasterized PDF or to a stream.

Different Ways to Save a Redacted File with .NET Document Redaction API

Save the redacted document to its original format

This sample code performs Word document redaction and shows how to save a Word document in its original format:

    using (Redactor redactor = new Redactor(@"sample.docx"))
{
    // Applying redactions
    redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
    // Saving to original format by adding the date as a suffix
    redactor.Save(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false, RedactedFileSuffix = DateTime.Now.ToShortDateString() });
}
    

Saving the redacted document as a rasterized PDF

You may save the file after Word document redaction as a rasterized PDF, please use the following code to do this:

    using (Redactor redactor = new Redactor(@"sample.docx"))
{
    // Applying redactions
    redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
    // Saving the redacted file as a rasterized PDF
    redactor.Save(new SaveOptions() { AddSuffix = false, RasterizeToPDF = true });
}     

We also provide Free Online Apps for instantly redacting PDF, Word, Excel, PowerPoint, OpenDocument, PNG, JPG, GIF, TIFF, and many other files using your mobile or desktop devices so, please be sure to check them out.

Looking for help?

Checkout our support channels for help with your questions related to Conholdate product API features and working.