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:

const redaction = require('@groupdocs/groupdocs.redaction');
const java = require('java');
const fs = require('fs');
const Color = java.import('java.awt.Color');

// Make a copy of sample file
fs.copyFileSync('Sample.docx', 'OverwrittenSample.docx');

const redactor = new redaction.Redactor('OverwrittenSample.docx');
try {
  const result = redactor.apply(new redaction.ExactPhraseRedaction(
    'John Doe',
    new redaction.ReplacementOptions(Color.RED)));
  if (result.getStatus() !== redaction.RedactionStatus.Failed) {
    const options = new redaction.SaveOptions();
    options.setAddSuffix(false);
    options.setRasterizeToPDF(false);
    // Save the document in original format overwriting original file
    redactor.save(options);
  }
} finally {
  redactor.close();
}
Binary file (DOCX, 17 KB)

Download full output

On this page