How to migrate to GroupDocs.Viewer 19.8 or higher

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 →

This page describes migration to the 19.8 version or later from the previous one.

Why to migrate

The main reasons to use the 19.8 version or later are as follows:

  • The Viewer class is a single entry point to manage the document rendering process to any supported file format instead of the ViewerHtmlHander/ViewerImageHander classes from previous versions.
  • The rendering speed improved significantly by saving the rendered page as it is rendered, not when all pages are rendered.
  • Product architecture is redesigned from scratch to decrease memory usage from 10% to 400% depending on the document type.
  • Document rendering options are simplified, so you can easily instantiate the proper option class and control document rendering and saving processes.

How to migrate

Here is a brief comparison of how to display a document in HTML form using old and new versions.

The following code snippet shows the old coding style:

//Get Configurations
ViewerConfig config = Utilities.GetConfigurations();

// Create html handler
ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);

// Guid implies that unique document name 
string guid = "sample.docx";

//Instantiate the HtmlOptions object
HtmlOptions options = new HtmlOptions();

//to get html representations of pages with embedded resources
options.IsResourcesEmbedded = true;

// Set password if document is password protected. 
if(!String.IsNullOrEmpty(DocumentPassword))
   options.Password = DocumentPassword;
            
//Get document pages in html form
List<PageHtml> pages = htmlHandler.GetPages(guid, options);

foreach (PageHtml page in pages)
{
    //Save each page at disk
    Utilities.SaveAsHtml(page.PageNumber + "_" + DocumentName, page.HtmlContent);
}
'Get Configurations
Dim config As ViewerConfig = Utilities.GetConfigurations()

' Create html handler
Dim htmlHandler As ViewerHtmlHandler = New ViewerHtmlHandler(config)

' Guid implies that unique document name 
Dim guid As String = "sample.docx"

'Instantiate the HtmlOptions object
Dim options As HtmlOptions = New HtmlOptions()

'to get html representations of pages with embedded resources
options.IsResourcesEmbedded = True

' Set password if document is password protected. 
If Not [String].IsNullOrEmpty(DocumentPassword) Then options.Password = DocumentPassword

'Get document pages in html form
Dim pages As List(Of PageHtml) = htmlHandler.GetPages(guid, options)

For Each page As PageHtml In pages
    'Save each page at disk
    Utilities.SaveAsHtml(page.PageNumber.ToString() & "_" + DocumentName, page.HtmlContent)
Next

The following code snippet shows the new coding style:

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

using (Viewer viewer = new Viewer("sample.docx"))
{
   HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources();
   viewer.View(options);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...
Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.docx")
            Dim options As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(options)
        End Using
    End Sub
End Module

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

p_1.html (228 KB)
p_2.html (110 KB)
p_3.html (142 KB)
p_4.html (885 KB)
p_5.html (86 KB)

Download full output