Load document from InputStream

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.Merger 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-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

There might be the case when source or target document is not physically located on the disk. Instead, you have the document in the form of a InputStream. In this case, to avoid the overhead of saving InputStream as a file on disk, GroupDocs.Merger provides a way to work with document streams directly. 
The following are the steps to be followed:

  • Obtain document InputStream; 
  • Pass opened source document stream to Merger class constructor.

Following code snippet describes this case.

try {
    InputStream stream = new FileInputStream("c:\\sample.docx");
    Merger merger = new Merger(stream);
    System.out.print("Document loaded from stream successfully.");
} catch (Exception e){
    throw new GroupDocsException(e.getMessage());
}