MHTML Converter – C# Examples
Convert MHTML in 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 for .NET 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 JPG in your C# application literally with two lines of code!
1// Open an existing MHTML file for reading
2using var stream = File.OpenRead(DataDir + "sample.mht");
3
4// Invoke the ConvertMHTML() method to convert MHTML to JPG
5Converter.ConvertMHTML(stream, new ImageSaveOptions(ImageFormat.Jpeg), Path.Combine(OutputDir, "convert-by-two-lines.jpg"));
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 JPG 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!