English

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

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

Try our APIs for FreeGet Temporary License

Secure and intelligent document redaction

Redaction is the process of obscuring or deleting classified information in a document. The redacted information is usually considered to be sensitive, private, or classified. Therefore, redaction is often used to maintain or improve file security and privacy by keeping sensitive information from getting compromised. Redaction may also be used to remove personal data from documents, such as social security numbers, addresses, or passwords for legal, financial, or official documents.

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 library, look no further than GroupDocs.Redaction for .NET. This 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 GroupDocs.Redaction for .NET 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 of the popular use cases for the redaction of data and classified information from your documents.

How to redact text using the exact phrase and regular expression?

Text redaction is the most commonly used option when it comes to concealing or removing important information from a document. This can be done for various reasons, such as protecting sensitive information or simply cleaning up a document before sharing it with someone. There are a few different ways to redact text, including using a replacement text (in place of the redacted content) or inserting colored boxes. 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.

How to redact text using the exact phrase and regular expression?

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

Learn to redact annotations or the text within annotations in your .NET redaction apps

Annotations can often contain sensitive data such as comments, notes, or even revisions. To ensure keeping the contents of your document annotations secure, you may need to redact them. GroupDocs.Redaction for .NET lets you redact the annotation text or completely remove the actual annotation itself.

Learn to redact annotations or the text within annotations in your .NET redaction apps

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

Redact private or sensitive information from your PNG, JPG, GIF, and TIFF images

When working with images, you may encounter a situation where you must redact or remove private information from them. This could be anything from a social security number to a person’s face of a person. Redaction for .NET can work as the perfect 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.

Redact private or sensitive information from your PNG, JPG, GIF, and TIFF images

Redact a specified area inside an image file

To redact a certain area in an image, please use the C# code shown below. While we are using a JPG image in this sample code, 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 GroupDocs.Redaction for .NET. 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();
       };
    }     

What are the different ways to save a redacted file?

When redacting a document or image, it is important to make sure that the information is hidden in such a way that it cannot be recovered or become visible. This helps maintain the integrity of the redacted content. So, once you are done redacting a file of your choice, the next phase is to save it appropriately. Using GroupDocs.Redaction for .NET, you can save the redacted file in its original format, overwrite the original file, and save it as a rasterized PDF or to a stream.

What are the different ways to save a redacted file?

Save the redacted document to its original format

This sample code shows how to save a Word document in its original format after redacting it:

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