Render to HTML

When rendering to HTML, GroupDocs.Viewer renders each page of the source document as a separate HTML document.

GroupDocs.Viewer for .NET provides two options to manage CSS, fonts, images, and other resources:

  1. HTML with external resources stores page resources as separate files. This allows reusing common resources and results in reducing page size and loading speed.
  2. HTML with embedded resources integrates page resources into HTML. This makes each document page self-sufficient but results in increasing page size and loading speed.

To render files to HTML, follow these steps:

  1. Create an instance of the Viewer class. Specify the source document path as a constructor parameter.
  2. Instantiate the HtmlViewOptions object. Specify a path to save the rendered pages.
  3. Call the View method of the Viewer object. Specify the HtmlViewOptions object as the parameter.

Rendering to HTML with external resources

The following code snippet shows how to render a .docx document to HTML with external resources:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

using (Viewer viewer = new Viewer("sample.docx"))
{
    // Create view options.
    var viewOptions = HtmlViewOptions.ForExternalResources();
    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.docx")
            ' Create view options.
            Dim viewOptions = HtmlViewOptions.ForExternalResources()
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

Rendering to HTML with embedded resources

The following code snippet shows how to render a .docx document to HTML with embedded resources:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

using (Viewer viewer = new Viewer("sample.docx"))
{
    // Create view options.
    var viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.docx")
            ' Create view options.
            Dim viewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

For details, please refer to the following pages: