MHTML Converter – Java

MHTML is a web page archive format that allows embedding multiple resources, such as images, CSS styles, audio, and video files, into a single file, typically with a .mht file extension. MHTML format allows a web page to be saved and sent as a single file, preserving its appearance and interactivity. It can be opened by most web browsers. But sometimes you want to Convert MHTML to get the advantages of other formats.

Aspose.HTML for Java provides a wide range of MHTML conversions to popular formats, such as PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF.

This section provides information on the list of supported MHTML conversions and how to perform them using convertMHTML() methods of the Converter class. It can be different scenarios, but any MHTML conversion can be made with a few required steps:

  1. Load an existing MHTML file. You can load MHTML from a file, stream, or URL.
  2. Create a Save Options object. You may customize the rendering process to get the desired result.
  3. Use one of the convertMHTML() methods and pass the required parameters to it.

Let’s consider the following code snippet that shows how to convert MHTML to PDF using our Java library:

1    // Open an existing MHTML file for reading
2    final  FileStream stream = File.openRead(StringExtensions.concat(getDataDir(),  "sample.mht"));
3    try
4    {;
5    }
6    finally { if (stream != null) ((IDisposable)stream).dispose(); }
7
8    // Сonvert MHTML to PDF
9    com.aspose.html.converters.Converter.convertMHTML(stream, new com.aspose.html.saving.PdfSaveOptions(), Path.combine(getOutputDir(), "sample-output.pdf"));    

Popular MHTML Conversions

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

Aspose.HTML provides a free online MHTML Converter that enables you to convert MHTML files to various popular formats. This tool can easily convert MHTML to PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF. The conversion process is simple and fast. You don’t need any additional software. The best part is that it’s completely free!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.