MHTML to XPS Conversion

In this article, you will find information on how to convert an MHTML to XPS and how to use XpsSaveOptions and ICreateStreamProvider parameters.

The static methods of the Converter class are primarily used as the easiest way to convert an MHTML code into various formats. You can convert MHTML to XPS in your C# application literally with a single line of code!

The following C# code snippet shows how to convert MHTML to XPS using Aspose.HTML for .NET.

  1. Open an existing MHTML file;
  2. Create an instance of XpsSaveOptions;
  3. Use the Converter.ConvertMHTML method of Converter class to save MHTML as a XPS file. You need to pass the MHTML file stream, XpsSaveOptions, and output file path to the Converter.ConvertMHTML method to convert MHTML to XPS .

Save Options

XpsSaveOptions allows you to customize the rendering process. You can specify the page sizemarginsCSS media-type, etc. The following example shows how to use XpsSaveOptions and create an XPS file with custom page-size and background color:

To learn more about XpsSaveOptions please read Fine-Tuning Converters article.

Output Stream Providers

If it is required to save files in the remote storage (e.g., cloud, database, etc.) you can implement ICreateStreamProvider interface to have manual control over the file creating process. This interface designed as a callback object to create a stream at the beginning of the document/page (depending on the output format) and release the early created stream after rendering document/page.

Aspose.HTML for .NET provides various types of output formats for rendering operations. Some of these formats produce a single output file (for instance PDF, XPS), others create multiple files (Image formats JPG, PNG, etc.).

The example below shows how to implement and use the your own MemoryStreamProvider in the application: