Convert Word Documents to HTML using Java

Word to HTML Java

In order to embed the content of Word documents into your applications, you might need to perform the conversion. The most widely opted conversions in such cases are Word to HTML or Word to image. In accordance with that, this article covers how to convert Word DOCX or DOC files to HTML using Java. Also, we’ll discuss how to keep resource files in a separate folder.

Java API for Word to HTML Conversion

For DOCX/DOC to HTML conversion, we will use Aspose.Words for Java. It is a powerful API to implement word processing features from within the Java applications. Furthermore, the API provides high-fidelity conversion of Word documents to HTML and other formats. You can either download the API or install it from Maven.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>21.10</version>
    <type>pom</type>
</dependency>

Convert a Word Document to HTML in Java

To convert a Word document to HTML, you only need to load the document and save it as an HTML file. The following are the steps to convert a Word DOCX file to HTML using Java.

The following code sample shows how to convert a Word document to HTML using Java.

Specify Resource Folder in Word to HTML Conversion

You can also configure the API to save the resource files in a separate folder. Moreover, you can keep fonts and images separately in different folders. The following are the steps to specify the resource folder.

The following code sample keeps resource files in a separate folder in Word to HTML conversion.

You can read more about working with resource folders in Word to HTML conversion.

Get a Free API License

You can use Aspose.Words for Java without evaluation limitations by getting a free temporary license.

Conclusion

In this article, you have learned how to convert Word DOCX or DOC files to HTML programmatically using Java. In addition to this, you have seen how to store resource files separately in Word to HTML conversion. Besides, you can read more about Aspose.Words for Java using the documentation. Furthermore, you can share your queries with us on our forum.

See Also