Nowadays, Markdown (MD) format is widely opted to write online articles, blogs, and documentation. However, its syntax becomes difficult to remember and write in the case of large-sized documents. To make things easier, you can write content in MS Word and then convert DOCX or DOC file to Markdown. To perform this conversion programmatically, this article covers how to convert Word documents to Markdown (.md) files using Java.
- Word to Markdown Converter Library
- Convert a Word Document to Markdown
- Customize Word to Markdown Conversion
Java Word to Markdown Converter Library
To convert DOCX/DOC files to Markdown format, we will use Aspose.Words for Java. The said API allows you to create and manipulate Word documents from within Java applications. Also, it provides a high-quality document converter to convert MS Word documents to other formats. You can download the API’s JAR or install it using the following Maven configurations.
<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.11</version>
<type>pom</type>
</dependency>
Convert a Word Document to Markdown in Java
The following are the steps to convert a Word DOCX file to Markdown format in Java.
- Load the Word file using Document class.
- Convert Word file to Markdown format using Document.save(string) method.
The following code sample shows how to convert a DOCX file to Markdown format using Java.
Customize Word to Markdown Conversion
You can also change the default behavior of the API for Word to Markdown conversion. For example, you can set the alignment of the content in the tables, specify a folder to keep images, and so on. The following are the steps to set different options in Word to Markdown conversion.
- Load the Word document using Document class.
- Create an object of MarkdownSaveOptions class.
- Set desired options such as MarkdownSaveOptions.setImagesFolder(string).
- Convert Word document to Markdown using Document.save(string, MarkdownSaveOptions) method.
The following code sample shows how to customize DOCX to Markdown conversion using Java.
Get a Free API License
You can use Aspose.Words for Java without evaluation limitations using a temporary license.
Conclusion
In this article, you have learned how to convert Word DOCX/DOC files to Markdown (.md) programmatically in Java. Moreover, you have seen how to modify Word to Markdown conversion using different options. You can also explore other features offered by Aspose.Words for Java using the documentation. In addition, you can feel free to ask your questions via our forum.