Document viewer - HTML Viewer
Document viewer can operate in different rendering modes, HTML, Image and PDF (see Features Overview for more information). 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 Java 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.
Viewer viewer = new Viewer("sample.docx"); HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(); viewer.view(viewOptions); viewer.close();
Document viewer - HTML Viewer (external resources)
The following code shows how to render document to HTML with external resources.
Viewer viewer = new Viewer("sample.docx"); HtmlViewOptions viewOptions = HtmlViewOptions.forExternalResources(); viewer.view(viewOptions); viewer.close();
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
- GroupDocs.Viewer for .NET samples, plugins and showcase
- Document Viewer for .NET MVC UI Example
Free Online App
Along with full-featured Java 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.