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#
- Setup Aspose.HTML for .NET package from NuGet.org
- Include the four required namespaces of the Aspose.HTML API
- Use SetLicense method to apply the API license
- Load Markdown (MD) file using Converter class into HTMLDocument object
- Save the output as an HTML file
- Load output HTML file into HTMLDocument object
- Specify XPS options using XpsRenderingOptions class
- Create an instance of XpsDevice class to render XPS output
- 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.