Save overwriting original file

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Redaction MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

On this page

The following example demonstrates how to save the redacted document, replacing an original file:

// Make a copy of sample file
Files.copy(new File("sample.docx").toPath(), new File("OverwrittenSample.docx").toPath(), StandardCopyOption.REPLACE_EXISTING);
// Apply redaction
final Redactor redactor = new Redactor("OverwrittenSample.docx");
try 
{
    RedactorChangeLog result = redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(java.awt.Color.RED)));
    if (result.getStatus() != RedactionStatus.Failed)
    {
        SaveOptions options = new  SaveOptions();
        options.setAddSuffix(false);
        options.setRasterizeToPDF(false);
        // Save the document in original format overwriting original file
        redactor.save(options);
    }
}
finally { redactor.close(); }
// Publish a distinct artifact for the docs output tab
Files.copy(new File("OverwrittenSample.docx").toPath(), new File("sample_overwritten.docx").toPath(), StandardCopyOption.REPLACE_EXISTING);
Binary file (DOCX, 17 KB)

Download full output

On this page