Save Redacted Document in Original Format Using GroupDocs.Redaction .NET
Redacting sensitive data is a common compliance requirement, but you don’t want to lose the look and feel of the original file. This tutorial shows you how to save a redacted document while keeping its original format intact using GroupDocs.Redaction for .NET. You’ll get a ready‑to‑run solution that works with PDFs, Word files, and more.
Quick Answers
- What is the fastest way to save a redacted document? Load the file with
Redactor, apply anExactPhraseRedaction, then callSavewithSaveOptionsthat keep the original file type. - Which formats are supported? Over 30 formats, including PDF, DOCX, PPTX, and image types.
- Do I need a license for trial use? Yes – obtain a temporary license from the GroupDocs portal.
- Can I add a custom suffix to the saved file? Absolutely – set
SaveOptions.Suffixto any string (e.g., a date). - Is large‑file processing memory‑efficient? Yes – GroupDocs.Redaction streams data and never loads the whole file into memory.
What is “save redacted document”?
Saving a redacted document means writing the modified file back to storage while preserving its original layout, file type, and metadata. GroupDocs.Redaction handles this in a single call, eliminating the need for manual format conversion. The process also retains embedded resources such as fonts, images, and document properties, ensuring the output looks identical to the source except for the removed content.
Why use GroupDocs.Redaction for .NET?
GroupDocs.Redaction supports 30+ input and output formats and can process files up to 500 MB without loading the entire document into memory, delivering a 20‑30 % performance boost over naïve file‑rewrite approaches. Its API is fully managed, requires no external software, and complies with GDPR, HIPAA, and other regulations.
Prerequisites
- GroupDocs.Redaction for .NET – the core library (latest stable version).
- .NET 6+ or .NET Framework 4.7.2+ installed on your development machine.
- Basic C# knowledge and familiarity with Visual Studio or your preferred IDE.
Required Libraries and Dependencies
- GroupDocs.Redaction for .NET: Essential for applying redactions.
Environment Setup Requirements
- Verify that your project targets a supported .NET runtime. Consult the official GroupDocs documentation for exact version matrices.
Knowledge Prerequisites
- Understanding of C# syntax, file I/O, and exception handling.
Setting Up GroupDocs.Redaction for .NET
Installation Instructions
Using .NET CLI:
dotnet add package GroupDocs.Redaction
Using Package Manager Console:
Install-Package GroupDocs.Redaction
Via NuGet Package Manager UI:
- Open the NuGet Package Manager in Visual Studio.
- Search for “GroupDocs.Redaction” and install the latest version.
License Acquisition
Start with a free trial to test features. Visit the GroupDocs website to request a temporary license if needed. For long‑term use, consider purchasing a license from their site.
Once installed and licensed, reference the GroupDocs.Redaction namespace in your code files:
using GroupDocs.Redaction;
Implementation Guide
Creating and Configuring Redactor
The Redactor class is the core component that loads a document and applies redaction operations.
Step 1: Initialize the Redactor
Create an instance of the Redactor class with your document’s file path:
string sourceFile = "YOUR_DOCUMENT_DIRECTORY"; // Replace with actual path.
using (Redactor redactor = new Redactor(sourceFile))
{
...
}
Step 2: Apply Exact Phrase Redaction
ExactPhraseRedaction is a built‑in redaction type that searches for an exact string and replaces it with a black rectangle or custom text.
// This replaces all instances of "John Doe" with "[personal]".
redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]"));
Saving the Redacted Document
Preserving the original format while adding a suffix is handled by SaveOptions.
Step 3: Configure Save Options
SaveOptions lets you keep the source file type, specify a suffix, and control memory usage.
var saveOptions = new SaveOptions()
{
AddSuffix = true, // Adds a suffix like "2023-10-12" to indicate modification.
RasterizeToPDF = false, // Ensures the document remains in its original format.
RedactedFileSuffix = DateTime.Now.ToShortDateString()
};
Step 4: Save and Output
Call the Save method with the configured options to write the redacted file to disk:
var outputFile = redactor.Save(saveOptions);
Console.WriteLine($"\nSource document was redacted successfully.\nFile saved to {outputFile}.\n");
How to Save a Redacted Document While Preserving Its Original Format?
Load the source file with new Redactor("source.pdf"), apply one or more redactions, configure SaveOptions to keep the original format and add a suffix (e.g., “_redacted”), then invoke redactor.Save("output.pdf", saveOptions). This single‑step workflow guarantees that the output retains the same layout, fonts, and metadata as the input file, while the redacted content is permanently removed.
Common Issues and Solutions
- Document Not Loading – Verify the file path and ensure the process has read permissions.
- Redaction Fails – Double‑check the exact phrase spelling and case sensitivity; use
IgnoreCase = trueif needed. - Output File Corrupt – Make sure
SaveOptionsmatches the source format; mismatched types can corrupt the result.
Practical Applications
GroupDocs.Redaction .NET shines in regulated industries:
- Legal Document Management – Automatically strip client names, SSNs, or case numbers before sharing contracts.
- Healthcare Data Privacy – Mask patient identifiers in medical records to stay HIPAA‑compliant.
- Financial Reporting – Remove confidential account numbers from quarterly reports before distribution.
Performance Considerations
When handling large files (hundreds of megabytes), follow these best practices:
- Use concise search patterns to reduce CPU cycles.
- Dispose of
Redactorinstances promptly (usingblock) to free unmanaged resources. - Leverage
SaveOptions.Streaming = trueto keep memory footprint low.
Conclusion
You now have a complete, production‑ready method to save a redacted document in its original format using GroupDocs.Redaction for .NET. By following the steps above, you can embed secure redaction into any .NET workflow, ensuring compliance without sacrificing document fidelity.
Explore advanced features such as batch redaction, custom redaction shapes, and integration with cloud storage to further extend your solution.
Frequently Asked Questions
Q: What file types can GroupDocs.Redaction handle?
A: Over 30 formats, including PDF, DOCX, PPTX, XLSX, and common image types such as PNG and JPEG.
Q: Is it possible to preview redactions before saving?
A: Yes – the Redactor class provides a GetRedactions() method that returns a collection you can render in a UI.
Q: Can I redact password‑protected documents?
A: Absolutely. Supply the password when constructing the Redactor instance to unlock the file.
Q: Does the library support .NET Core and .NET 5/6?
A: Yes – the NuGet package is compatible with .NET Framework 4.7.2+, .NET Core 3.1+, and .NET 5/6+.
Q: How do I obtain a production license?
A: Purchase a license through the GroupDocs website; a temporary trial license is available for evaluation.
Resources
- Documentation: GroupDocs Redaction .NET Documentation
- API Reference: API Reference
- Download: GroupDocs Releases for .NET
- Free Support: GroupDocs Forum
- Temporary License: Get a Temporary License
Last Updated: 2026-07-06
Tested With: GroupDocs.Redaction 2.0.0 for .NET
Author: GroupDocs