MHTML Converter – C# Examples

Contents
[ Hide Show ]

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!

You can download the complete examples and data files from GitHub.

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

 1using System.IO;
 2using Aspose.Html.Converters;
 3using Aspose.Html.Rendering.Image;
 4using Aspose.Html.Saving;
 5...
 6
 7    // Open an existing MHTML file for reading
 8    using var stream = File.OpenRead(DataDir + "sample.mht");
 9    
10    // Invoke the ConvertMHTML() method to convert MHTML to PNG
11    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.

                
            

Aspose.HTML offers a free online MHTML Converter for converting MHTML files to a variety of popular formats. You can easily convert MHTML to PDF, MHTML to XPS, MHTML to JPG, MHTML to PNG, MHTML to BMP, MHTML to TIFF, and MHTML to GIF. Just select the file, choose the format to convert, and you’re done. It’s fast and completely free!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.