MHTML Converter | C#

Files with MHTML extension represent a web page archive format that a number of different applications can create. The format is known as archive format because it saves the web HTML code and associated resources in a single file. These resources include anything linked to the webpage such as images, applets, animations, audio files and so on. MHTML files can be opened in a variety of applications such as Internet Explorer and Microsoft Word. The actual specifications of the format are as detailed by RFC 2557.

The main highlight of Aspose.HTML is a conversion feature. The Aspose.Html.Converters namespace implements easy access to conversion methods. This section provides information on the list of supported MHTML conversion scenarios and how to perform them using the Converter class that groups all low-level conversion operations in a single class to make them comfy and easy to use. For example, you can convert MHTML to PNG in your C# application literally with two lines of code!

Please take a look over the following C# code snippet that shows the MHTML to PNG conversion using the ConvertMHTML(stream, options, outputPath) method.

using System.IO;
using Aspose.Html.Converters;
using Aspose.Html.Rendering.Image;
using Aspose.Html.Saving;

    // Open an existing MHTML file for reading
    using var stream = File.OpenRead(DataDir + "sample.mht");
    // Invoke the ConvertMHTML() method to convert MHTML to PNG           
    Converter.ConvertMHTML(stream, new ImageSaveOptions(), Path.Combine(OutputDir, "convert-by-two-lines.png"));

In the example, we use the OpenRead(path) method of System.IO.FileStream class to open and read an MHTML file from the file system at the specified path. You need to pass the MHTML file stream, ImageSaveOptions, and output file path to the ConvertMHTML() method for MHTML to PNG conversion. Note: You need to specify the path to the output file in your local file system (outputPath). Also, for OpenRead(path), you need to provide the path to a source MHTML file in your local file system.

Online MHTML Converter

You can convert MHTML to other formats with Aspose.HTML for .NET API in real time. First, load an MHTML file from your local drive and then run the example. In this example, the save options are set by default. You will immediately receive the conversion result as a separate file.

Code example in C# to convert document formats
Input file
Upload a file you want to convert
Output format
Select the target format