Load document from 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.Viewer 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-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

On this page

You can load a document from a stream without saving it as a file on a disk. You can use this feature to load a document from different sources like a URL, FTP, and so on.

To load a document from a stream, follow these steps:

  1. Implement a method to get the document stream.
  2. Call the Viewer class constructor. Specify the method implemented in the previous step.

The following code snippet shows how to load a document from a stream:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def load_document_from_stream():
    # Open document stream
    stream = open("sample.docx", "rb")

    # Render a document from the stream.
    with Viewer(stream) as viewer:
        options = HtmlViewOptions.for_embedded_resources("page_{0}.html")
        viewer.view(options)

if __name__ == "__main__":
    load_document_from_stream()

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

page_1.html (253 KB)
page_2.html (110 KB)
page_3.html (148 KB)
page_4.html (1001 KB)
page_5.html (86 KB)

Download full output

See also Load document from URL for a concrete example of downloading a document into a BytesIO stream and rendering it without ever writing it to disk.

On this page