Document viewer - HTML Viewer

Document viewer can operate in different rendering modes, HTML, Image and PDF. This article will describe on how to view documents in HTML mode with HTML Viewer.

In HTML rendering mode all pages of the source documents are rendered as separate HTML pages.

For HTML rendering mode following HtmlViewOptions are available:

  • HtmlViewOptions.ForEmbeddedResources - all resources such as styles, fonts, and graphics are integrated into an HTML pages.

    • Pros: No external files which makes more convenient to save result to a stream.
    • Cons: Larger page size and as a result slower loading and rendering of an HTML document in a browser.
  • HtmlViewOptions.ForExternalResources - all the resources, such as styles, fonts, and graphics are external.

    • Pros: Smaller page size as a page includes only markup and links to external resources. Faster HTML document loading and rendering in a browser as browsers can load multiple external resources simultaneously.
    • Cons: External files, since all resources will be stored next to an HTML page or in a specific directory.

With GroupDocs.Viewer for .NET API HTML rendering became simple and intuitive. Just follow these steps:

  • Create a new instance of the Viewer class and pass the source document path as a constructor parameter.
  • Instantiate the HtmlViewOptions object according to your requirements (for embedded or external HTML resources) and specify saving path format for rendered document pages.
  • Call View method of Viewer class instance and pass HtmlViewOptions to it.

Document viewer - HTML Viewer (embedded resources)

The following code shows how to render document to HTML with embedded resources.

using (Viewer viewer = new Viewer("sample.docx"))
{
   HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
   viewer.View(viewOptions);
}

Document viewer - HTML Viewer (external resources)

The following code shows how to render document to HTML with external resources.

using (Viewer viewer = new Viewer("sample.docx"))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForExternalResources();
    viewer.View(viewOptions);
}

More resources

Advanced Usage Topics

To learn more about document viewing features, please refer to the advanced usage section.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.