Redact documents with GroupDocs.Redaction
Leave feedback
On this page
GroupDocs.Redaction removes sensitive information from a document rather than merely hiding it — the redacted text is gone from the file, not covered by a black box you can drag away. It redacts text, metadata, annotations and image regions, and can rasterise the result to PDF so the original content cannot be recovered.
Redact an exact phrase
ExactPhraseRedaction replaces every occurrence of a phrase. ReplacementOptions decides what takes its place. The contract names its engagement Project Northlight in the body — that codename is what a redacted copy has to lose.
usingSystem;usingSystem.IO;usingGroupDocs.Redaction;usingGroupDocs.Redaction.Options;usingGroupDocs.Redaction.Redactions;using(Redactorredactor=newRedactor("contract-v1.docx")){RedactorChangeLogresult=redactor.Apply(newExactPhraseRedaction("Project Northlight",newReplacementOptions("[REDACTED]")));Console.WriteLine("Status: "+result.Status);if(result.Status!=RedactionStatus.Failed){// Save() has no path overload: SaveOptions writes back over the source.// Write to a stream to keep the original intact.using(FileStreamoutput=File.Create("redaction-exact-phrase.docx")){redactor.Save(output,newRasterizationOptions{Enabled=false});}}}
contract-v1.docx is the sample file used in this example. Click here to download it.
A regex redaction catches patterns rather than literals — account numbers, amounts, email addresses — which is what most compliance rules are actually written against.
usingSystem;usingSystem.IO;usingGroupDocs.Redaction;usingGroupDocs.Redaction.Options;usingGroupDocs.Redaction.Redactions;using(Redactorredactor=newRedactor("contract-v1.docx")){// Any currency amount such as "120,000 USD"RedactorChangeLogresult=redactor.Apply(newRegexRedaction(@"\d{1,3}(,\d{3})*\s?USD",newReplacementOptions("[AMOUNT]")));Console.WriteLine("Status: "+result.Status);if(result.Status!=RedactionStatus.Failed){// Save() has no path overload: SaveOptions writes back over the source.// Write to a stream to keep the original intact.using(FileStreamoutput=File.Create("redaction-regex.docx")){redactor.Save(output,newRasterizationOptions{Enabled=false});}}}
contract-v1.docx is the sample file used in this example. Click here to download it.
Redacting the visible text is only half the job — the author, the revision history and the original filename usually live in the metadata. EraseMetadataRedaction clears them.
usingSystem;usingSystem.IO;usingGroupDocs.Redaction;usingGroupDocs.Redaction.Options;usingGroupDocs.Redaction.Redactions;using(Redactorredactor=newRedactor("contract-v1.docx")){RedactorChangeLogresult=redactor.Apply(newEraseMetadataRedaction(MetadataFilters.All));Console.WriteLine("Status: "+result.Status);if(result.Status!=RedactionStatus.Failed){// Save() has no path overload: SaveOptions writes back over the source.// Write to a stream to keep the original intact.using(FileStreamoutput=File.Create("redaction-metadata.docx")){redactor.Save(output,newRasterizationOptions{Enabled=false});}}}
contract-v1.docx is the sample file used in this example. Click here to download it.
Setting Enabled = true on RasterizationOptions converts each page to an image inside a PDF. It is the strongest option — no text layer survives for anyone to recover — at the cost of the result no longer being searchable or editable. The SaveOptions overload spells the same thing RasterizeToPDF.
Learn more
GroupDocs.Redaction also redacts image areas, deletes or rewrites annotations, removes whole pages, applies several redactions in one pass, and supports custom redaction policies loaded from configuration.