Use redaction callback

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

In order to reject specific changes during redaction process or to keep a full log of changes in the document, you need to pass a callback implementing IRedactionCallback into RedactorSettings. The interface contains only one method, acceptRedaction, which receives detailed information about the proposed redaction and returns a Boolean value — accepted or not.

Below, we create a callback with java.newProxy, dumping changes to the console:

const redaction = require('@groupdocs/groupdocs.redaction');
const java = require('java');

const callback = java.newProxy('com.groupdocs.redaction.redactions.IRedactionCallback', {
  acceptRedaction: function (description) {
    let message = description.getRedactionType() + ' redaction, '
      + description.getActionType() + ' action, item '
      + description.getOriginalText() + '. ';
    if (description.getReplacement() !== null) {
      message += 'Text ' + description.getReplacement().getOriginalText()
        + ' is replaced with ' + description.getReplacement().getReplacement() + '. ';
    }
    console.log(message);
    return true;
  }
});

The instance of this callback is passed to a constructor of the Redactor class:

const redaction = require('@groupdocs/groupdocs.redaction');

const redactor = new redaction.Redactor(
  'Sample.docx',
  new redaction.LoadOptions(),
  new redaction.RedactorSettings(callback));
try {
  redactor.apply(new redaction.ExactPhraseRedaction(
    'John Doe',
    new redaction.ReplacementOptions('[personal]')));
  redactor.save();
} finally {
  redactor.close();
}

Sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 1012 KB)

Download full output

On this page