This blog post is for you if you want to develop a Word to HTML converter for your business application. You may install this Java Word library to convert Docx files to other popular formats such as HTML, PNG, PDF, and more. However, by the end of this tutorial, you should have a good knowledge of this file conversion Java library. Therefore, let’s start the article and learn how to convert Word to HTML in Java programmatically.
The following points will be covered:
Java Word library installation
The installation process of this library is very developer-friendly as you find comprehensive documentation regarding development and installation. So, you can download the JAR file or install this library using the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://releases.aspose.com/java/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>22.10</version> <classifier>jdk17</classifier> </dependency>
Convert Word to HTML in Java
You are all set to go for writing source code in your Java application to build Word to HTML converter programmatically.
Following are the steps to convert Word to HTML:
- Create an instance of the Document class and load the source Word file.
- Initialize an object of the HtmlSaveOptions class to specify additional options when saving a document into the HTML formats.
- Invoke the setExportRoundtripInformation to specify whether to write the roundtrip information when saving to HTML.
- If the value of the setExportFontResources method is true, font resources will be exported to HTML.
- Call the setExportFontsAsBase64 method to specify whether font resources should be embedded in HTML in Base64 encoding.
- Now, the save method will save the Word document in the HTML format.
Copy & paste the following code into your main file:
The output can be seen in the image below:
Get a Free License
You can avail a free temporary license to try the API without evaluation limitations.
We can end this blog post here. Hopefully, you have enjoyed the article and have learned how to convert Word to HTML in Java programmatically. There are many other features exposed by this Java Word library so do not forget to visit the documentation.
Moreover, we suggest you follow our Getting Started guide.
Finally, conholdate.com is writing new blog posts. So, please stay in touch for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
How do I convert a DOCX to HTML?