Convert Word to HTML using JAVA
HTML (Hyper Text Markup Language) is designed to display documents in a web browser. This article will demonstrate how to convert Word to HTML using Free Spire.Doc for Java.
Import JAR Dependency
Method 1: Download the Free Spire.Doc for Java and unzip it. Then add the Spire.Doc.jar file to your Java application as dependency.
Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
Convert Word to HTML
The following are the detailed steps to convert Word to HTML:
- Create a Document instance.
- Load a Word document using Document.loadFromFile() method.
- Save the document as an HTML file using Document.saveToFile() method.
import com.spire.doc.*;
public class WordToHtml {
public static void main(String[] args) {
//Create a Document instance
Document document = new Document();
//Load a Word document
document.loadFromFile("Film.docx");
//Save the document as HTML
document.saveToFile("toHtml.html", FileFormat.Html);
}
}