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:
- Load an existing MHTML file. You can load MHTML from a file, stream, or URL.
- Create a Save Options object. You may customize the rendering process to get the desired result.
- 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
- Convert MHTML to PDF – Learn how to convert MHTML to PDF using Java library.
- Convert MHTML to XPS – Consider various MHTML to XPS conversion scenarios in Java code.
- Convert MHTML to JPG – Learn how to convert MHTML to JPG with Aspose.HTML for Java, and you can easily use the Java code described here to convert MHTML to PNG, MHTML to BMP, MHTML to GIF, and MHTML to TIFF.
- Convert MHTML to PNG – Know how to convert MHTML to PNG using the
convertMHTML()
methods of the Converter class and how to applyImageSaveOptions
.
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!