How to Convert Markdown to XPS using Java

This simple and brief topic focuses on how to convert Markdown to XPS using Java. We also name Markdown files as MD files and you can easily convert MD to XPS in Java using simple API calls that are not dependent on any pre-requisite software or third party tool. The code implementation can be used in Java based applications running in Windows, Linux and macOS platforms.

Steps to Convert Markdown to XPS using Java

  1. Add Aspose.HTML JAR file from the Maven Repository in your project
  2. Create an HTMLDocument Class object instance to load the Markdown file
  3. Convert the Markdown MD file as intermediate HTML file
  4. Load the intermediate HTML file using HTMLDocument object instance
  5. Save the intermediate HTML file to XPS format on disk

The MD file is in fact a normal text file using Markdown language comprising of inline text symbols for text formatting, fonts, headers and indentations. In order to export Markdown to XPS using Java, in first step we will load the Markdown file and convert that to an intermediate HTML file on disk. Then in second step, we will set XPS options and save the intermediate HTML to XPS using Java. This two step process is achieved using simple API calls in Java.

Code to Export Markdown to XPS in Java

In the previous topic, we have learnt how to create HTML file using Java. In this topic we have focuses on Markdown to XPS conversion using Java in two step approach.

 English