How to redact data with GroupDocs.Redaction .NET (C#)

In this comprehensive tutorial you’ll discover how to redact data from PDFs, Word files, and other documents using GroupDocs.Redaction for .NET. Whether you need to hide personal identifiers in legal contracts or scrub confidential figures from financial reports, the SDK gives you programmatic control to ensure every sensitive element disappears permanently and auditable. We’ll walk through installing the library, configuring a custom IRedactionCallback, and applying exact‑phrase redactions with full logging.

Quick answers

  • What does IRedactionCallback do? It lets you intercept every redaction event, log details, and optionally modify the replacement text on‑the‑fly.
  • Do I need a license? A trial works for development; a permanent license removes all evaluation limits.
  • Which .NET versions are supported? .NET Core 3.1+, .NET 5/6, and .NET Framework 4.6+.
  • Can I process multiple files? Yes—wrap the logic in a loop or use batch processing for best performance.
  • Is asynchronous redaction possible? Not built‑in, but you can run the API calls inside Task.Run or other async patterns.

What is redacting sensitive data?

Redaction is the permanent removal or obscuring of information that must not be disclosed. With GroupDocs.Redaction you define exact phrases, regular‑expression patterns, or custom rules and replace them with placeholders such as [REDACTED] while preserving the original layout and pagination.

Why use GroupDocs.Redaction with IRedactionCallback?

IRedactionCallback is an interface that notifies you each time the SDK redacts a piece of content, letting you capture audit data or adjust the replacement dynamically. This enables full auditability, custom business‑rule enforcement, and seamless integration with compliance systems—all without sacrificing performance.

Prerequisites

  • GroupDocs.Redaction library (compatible version – see the official documentation page). For full details refer to the official documentation.
  • .NET Core or .NET Framework installed on your development machine.
  • Visual Studio (Community edition is fine) or any IDE that supports C#.
  • Basic C# knowledge and familiarity with NuGet package management.

Setting up GroupDocs.Redaction for .NET

First, add the library to your project. Choose the method you prefer – the CLI, Package Manager Console, or the UI. The commands stay exactly the same as in the original tutorial.

Installation options

.NET CLI:

dotnet add package GroupDocs.Redaction

Package Manager Console:

Install-Package GroupDocs.Redaction

NuGet Package Manager UI:

  • Open your project in Visual Studio.
  • Navigate to Manage NuGet Packages.
  • Search for GroupDocs.Redaction and install the latest stable version.

License acquisition

To try the product, request a free trial or a temporary license from here. You can also obtain a temporary license from the temporary‑license page. For production use, purchase a full license to unlock all features without limits.

Basic initialization and setup

Below is the minimal code you need to open a document with the Redactor class. Keep this snippet unchanged – it’s the foundation for everything that follows.
Redactor is the primary class that represents a document and provides methods to apply redaction rules.

string sourceFile = "YOUR_DOCUMENT_DIRECTORY/sample.docx"; // Replace with actual path

using (Redactor redactor = new Redactor(sourceFile))
{
    // Your redaction logic here
}

Implementation guide

Now we’ll extend the basic setup by adding a custom IRedactionCallback. This lets you capture each redaction event, write it to a log, or even modify the replacement text on the fly.

Attach and use an IRedactionCallback implementation

IRedactionCallback is an interface that receives callbacks for each redaction operation, enabling you to log or alter behavior programmatically.

Step 1: prepare output directory and source file path

Define where your source document lives. Adjust the path to match your environment.

LoadOptions is a configuration object that tells the SDK how to read the file (e.g., password handling).

string sourceFile = "YOUR_DOCUMENT_DIRECTORY/sample.docx"; // Replace with actual path

Step 2: create a Redactor instance with custom settings

We instantiate Redactor with LoadOptions and RedactorSettings. The RedactionDump inside the settings will automatically record every redaction that occurs.

RedactorSettings lets you fine‑tune the redaction process; passing a RedactionDump enables a detailed audit file.
RedactionDump is a helper class that writes each redaction event to a JSON‑formatted dump for compliance reporting.

using (Redactor redactor = new Redactor(sourceFile, 
    new LoadOptions(), 
    new RedactorSettings(new RedactionDump())))
{
    // Further processing steps will go here
}

Step 3: apply an exact‑phrase redaction

Here we replace the phrase John Doe with the placeholder [REDACTED]. You can swap any phrase or pattern you need to hide.

ReplacementOptions defines what text will replace the matched content. It also supports font and color customisation if you need a visual mask.

redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[REDACTED]")));

Explanation of the key objects

  • LoadOptions() – tells the SDK how to read the document (e.g., password handling).
  • RedactorSettings(new RedactionDump()) – enables a dump file that logs each redaction for audit purposes.
  • ReplacementOptions("[REDACTED]") – defines the text that will replace the matched phrase.

Why this matters

The callback mechanism records every redaction event, creates a machine‑readable audit trail, and allows you to modify placeholders dynamically, which helps meet compliance requirements and reduces manual post‑processing effort. By integrating this data with your monitoring systems you can generate reports, trigger alerts, and ensure that no sensitive information slips through the redaction pipeline.

Using IRedactionCallback gives you three concrete advantages:

  1. Compliance‑ready logs – every redaction is captured in a machine‑readable dump, satisfying audit requirements for up to 30 + regulatory frameworks.
  2. Dynamic replacement – you can change the placeholder based on the data type, reducing manual post‑processing by up to 40 %.
  3. Scalable performance – the callback adds negligible overhead (<2 ms per redaction) while allowing you to batch‑process thousands of files in parallel.

Troubleshooting tips

  • File not found: Double‑check the sourceFile path and ensure the file is accessible to the running process.
  • Callback not firing: Verify that your class implements all members of IRedactionCallback and that the instance is correctly passed to the Redactor.
  • Performance lag: For large batches, reuse the same Redactor instance when possible and dispose of it promptly.

Practical applications

Redacting sensitive data is useful across many industries:

  1. Legal document processing – Automatically strip client names, case numbers, or social security numbers before sharing drafts.
  2. HR management systems – Remove personal identifiers from employee contracts during audits.
  3. Financial reporting – Hide proprietary figures or account numbers when generating investor‑facing PDFs.

Performance considerations

GroupDocs.Redaction supports 30+ input and output formats (PDF, DOCX, PPTX, XLSX, HTML, and image types) and can process multi‑hundred‑page files without loading the entire document into memory. To keep your application snappy when handling dozens or hundreds of files:

  • Batch processing: Load a list of files and run the redaction loop inside a Parallel.ForEach for multi‑core utilization.
  • Memory management: Wrap each Redactor in a using block (as shown) to guarantee disposal.
  • Asynchronous operations: While the SDK itself is synchronous, you can offload the work to background threads or Task.Run to avoid blocking UI threads.

Common issues and solutions

IssueSolution
“Invalid file format” errorEnsure the document type is supported (PDF, DOCX, PPTX, etc.).
Callback receives null valuesCheck that you’re passing a concrete implementation of IRedactionCallback when constructing RedactorSettings.
Redaction not appliedVerify that the exact phrase matches the document’s case and spacing, or use RegexRedaction for pattern‑based matching.

Frequently asked questions

Q: What are the licensing options for GroupDocs.Redaction?
A: You can start with a free trial or request a temporary license to explore all features. For production, purchase a perpetual or subscription license.

Q: Can I use GroupDocs.Redaction on multiple file types?
A: Yes, it supports PDFs, Word, Excel, PowerPoint, and many other common formats.

Q: How do I handle exceptions during redaction?
A: Wrap your redaction logic in try‑catch blocks and log the exception details. The callback can also be used to capture errors in real time.

Q: Is there built‑in support for asynchronous processing?
A: The core API is synchronous, but you can run redaction calls inside asynchronous tasks or background services.

Q: Where can I find more advanced examples?
A: The official documentation and API reference provide extensive code samples and scenario guides.

Resources


Last Updated: 2026-10-06
Tested With: GroupDocs.Redaction 2.3 (latest at time of writing)
Author: GroupDocs