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.

final Redactor redactor = new Redactor("sample.docx");
try 
{
    // Here we can use document instance to perform redactions
    RedactorChangeLog result = redactor.apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(java.awt.Color.RED)));
    if (result.getStatus() != RedactionStatus.Failed)
    {
        // Save the document to a stream and convert its pages to images
        final FileOutputStream fileStream = new FileOutputStream("redacted-sample.pdf");
        try 
        {
            RasterizationOptions options = new  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