Convert HTML or MHTML to XPS Programmatically in C#

Convert HTML MHTML to XPS

HTML files are used over the web for presenting and formatting information. You can convert HTML files to XPS files programmatically using C#. The following use cases elaborate different conversion scenarios:

HTML/MHTML to XPS Converter – C# API Installation

Aspose.HTML for .NET API supports working with HTML files and several other file formats. You can install the API by downloading the DLL file from the New Releases section, or with the following NuGet installation command in Visual Studio:

PM> Install-Package Aspose.Html

Convert HTML/MHTML to XPS File Programmatically using C#

You can convert HTML or MHTML file to an XPS file with the following steps:

  1. Load input HTML file with HTMLDocument class.
  2. Initialize XpsSaveOptions instance.
  3. Convert HTML or MHTML to XPS.

The code below shows how to convert HTML to XPS file programmatically using C#:

Convert HTML/MHTML to XPS with advanced options Programmatically with C#

You have already learned the basic conversion use case. The API offers several advanced options to perform the conversion. Please follow the steps below for converting HTML/MTHML file to XPS:

  1. Load input HTML file.
  2. Instantiate XpsSaveOptions object.
  3. Set different rendering options.
  4. Convert input file to XPS with ConvertHTML method.

The following code explains how to convert HTML or MHTML files to XPS files with advanced options programmatically using C#:

HTML from URL link to XPS Conversion in C#

Online content is present over the web in the form of HTML files. You can directly convert HTML from URL to an XPS file using C#. You would not need to download the file manually, instead follow the steps below:

  1. Specify URL for input HTML.
  2. Load input HTML with HTMLDocument class.
  3. Initialize XpsSaveOptions class object.
  4. Convert HTML from URL to XPS file.

The code below elaborates how to convert the HTML from URL link to XPS file programmatically using C#:

Get Free API License

You can request Free Temporary License to evaluate the API without any limitations.

Conclusion

In conclusion, you have learned how to convert HTML files to XPS documents programmatically using C#. You can utilize this feature in your .NET or .NET Core based applications using any of the supported languages. Moreover, you can explore other features of the API by visiting the Documentation. Please feel free to write back to us at the Free Support Forum in case of any queries.

See Also

Create or Fill HTML Form with Submit Button using C#