How to migrate to GroupDocs.Viewer 19.8 or higher
Leave feedback
On this page
This article contains information about migration from the legacy API to GroupDocs.Viewer 20.1 or higher.
Why To Migrate
Here are the key reasons to use the new updated API provided by GroupDocs.Viewer for Java since version 20.1:
Viewer class introduced as a single entry point to manage the document rendering process to any supported file format (instead of ViewerHtmlHander / ViewerImageHander classes from previous versions).
The overall rendering speed improved dramatically by saving rendered page as soon as it was rendered, not when all pages list were rendered.
Product architecture was redesigned from scratch in order to decreased memory usage (from 10% to 400% approx. depending on document type).
Document viewing options simplified so it’s easy to instantiate proper options class and control over document rendering and saving processes.
How To Migrate
Here is a brief comparison of how to display document into HTML form using old and new API.
Using legacy API
//Get Configurations
ViewerConfigconfig=Utilities.getConfigurations();// Create html handler
ViewerHtmlHandlerhtmlHandler=newViewerHtmlHandler(config);// Guid implies that unique document name
Stringguid="sample.docx";// Document password
StringdocumentPassword="password";//Instantiate the HtmlOptions object
HtmlOptionsoptions=newHtmlOptions();//to get html representations of pages with embedded resources
options.setResourcesEmbedded(true);// Set password if document is password protected.
if(documentPassword!=null&&!documentPassword.isEmpty()){options.setPassword(documentPassword);}//Get document pages in html form
List<PageHtml>pages=htmlHandler.getPages(guid,options);for(PageHtmlpage:pages){//Save each page at disk
Utilities.saveAsHtml(page.getPageNumber()+"_"+documentName,page.getHtmlContent());}
Using new API
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.HtmlViewOptions;importcom.groupdocs.viewer.options.LoadOptions;importcom.groupdocs.viewer.options.ViewInfoOptions;importcom.groupdocs.viewer.results.Page;importcom.groupdocs.viewer.results.ViewInfo;// ...
LoadOptionsloadOptions=newLoadOptions();loadOptions.setPassword("password");try(Viewerviewer=newViewer("sample.docx",loadOptions)){HtmlViewOptionsoptions=HtmlViewOptions.forEmbeddedResources("page_{0}.html");viewer.view(options);finalViewInfoviewInfo=viewer.getViewInfo(ViewInfoOptions.forHtmlView());finalList<Page>pages=viewInfo.getPages();for(Pagepage:pages){finalintpageNumber=page.getNumber();System.out.println("Page number: "+pageNumber+", file saved as 'page_"+pageNumber+".html'");}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.