Load from stream

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:

using System.IO;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

Stream stream = GetStream("sample.docx"); // TODO: implement this method

// Render a document from the stream.
using (Viewer viewer = new Viewer(stream))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(viewOptions);
}
Imports System.IO
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Dim stream As Stream = GetStream("sample.docx") ' TODO: implement this method
    
        ' Render a document from the stream.
        Using viewer As Viewer = New Viewer(stream)
            Dim viewOptions As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

Please refer to the following pages for examples: