In this simple topic you will learn, how to convert Word Document to HTML using Java. The following simple steps can be used to export DOCX to HTML in Java in any common operating system like MS Windows, Ubuntu, or macOS using simple API calls.
Steps to Convert Word Document to HTML using Java
- Add Aspose.Words JAR file reference using Maven repository
- Instantiate the Document Class object to load source document
- Specify different HtmlSaveOptions including Page Margins, CssStyleSheet and Page Setup etc.
- Export DOCX to HTML in Java using save method
In the following sample code, we will first load the source DOCX using Document class instance. Then using HtmlSaveOptions class instance, we will set the CssStyleSheetType, ExportPageMargins and ImageResolution. Finally, using save method we will generate HTML from DOCX in Java.
Code to Export DOCX to HTML in Java
In this sample code, we have loaded the source DOCX using an instance of Document class. The HtmlSaveOptions class instance can be used to set different options like encoding, SVG options, version and many other properties. Finally, we export DOCX to HTML using Java.
In previous topic of how to convert DOCX to TIFF using Java, we focused on rendering DOCX to TIFF. Whereas, in this topic, we have learnt how to generate HTML from DOCX using Java.