Save to stream

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

You might need to save a document to any custom file at any location on the local disc or a even a Stream.

The following example demonstrates how to save a document to any location.

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

const redactor = new redaction.Redactor('Sample.docx');
try {
  const result = redactor.apply(new redaction.ExactPhraseRedaction(
    'John Doe',
    new redaction.ReplacementOptions(Color.RED)));
  if (result.getStatus() !== redaction.RedactionStatus.Failed) {
    const fileStream = new FileOutputStream('C:\\Temp\\sample_output_file.pdf');
    try {
      const options = new redaction.RasterizationOptions();
      options.setEnabled(true);
      redactor.save(fileStream, options);
    } finally {
      fileStream.close();
    }
  }
} finally {
  redactor.close();
}

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

Binary file (PDF, 1003 KB)

Download full output

On this page