How to Convert Markdown to XPS in C#

In this step by step tutorial, you’ll learn how to convert Markdown to XPS in C#. We’ll first convert Markdown to HTML in C# and then use C# code to convert HTML to XPS file format.

Steps to Convert Markdown to XPS in C#

  1. Setup Aspose.HTML for .NET package from NuGet.org
  2. Include the four required namespaces of the Aspose.HTML API
  3. Use SetLicense method to apply the API license
  4. Load Markdown (MD) file using Converter class into HTMLDocument object
  5. Save the output as an HTML file
  6. Load output HTML file into HTMLDocument object
  7. Specify XPS options using XpsRenderingOptions class
  8. Create an instance of XpsDevice class to render XPS output
  9. Render the loaded HTML file as XPS file format

The conversion from Markdown (MD) file format to XPS is done in two steps using a single Aspose.HTML for .NET API. In the first step, MD file is converted to HTML, and then HTML is converted to XPS file format. The conversion process is very simple and easy.

Code to Convert Markdown to XPS in C#

The above code shows that both conversions require HTMLDocument object. In the Markdown to HTML conversion, we’re using Converter class. While, for the HTML to XPS conversion, we’re using an XpsDevice object which helps render the HTML as XPS document. The above C# code sample works fine with any .NET platform and tools.

 English