MHT files are used to keep images, text, CSS, and other related resources in a single webpage. In some use cases, you might want to convert an HTML file to MHT format. Accordingly, this article covers how to convert HTML to MHT format programmatically in Java.
- HMTL to MHT File Converter – Java API Installation
- Convert HTML to MHT or MHTML in Java
- Convert HTML to MHT with Advanced Options in Java
HTML to MHT File Converter – Java API Installation
Aspose.HTML for Java API can be used to work with HTML, MHTML, XPS, and other supported file formats. You can download the JAR files from the Downloads page or using the following configurations in the pom.xml file of your application:
<repositories> <repository> <id>snapshots</id> <name>repo</name> <url>http://repository.aspose.com/repo/</url> </repository> </repositories>
<dependencies> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-html</artifactId> <version>21.12</version> <classifier>jdk16</classifier> </dependency> </dependencies>
Convert HTML to MHT or MHTML in Java
You need to follow the steps below for converting an HTML page to an MHT or MHTML file:
- Create an object of the MHTMLSaveOptions class.
- Save the output MHT or MHTML file with the ConvertHTML method.
The code sample below explains how to convert an HTML file to MHT or MHTML file programmatically in Java:
Convert HTML to MHT with Advanced Options in Java
You can enhance the process of converting the HTML file to MHT format by using the properties exposed by the MHTMLSaveOptions class. Please follow the steps below for converting HTML to an MHT file with advanced options:
- Initialize an instance of the MHTMLSaveOptions class.
- Specify the properties for the output MHT file.
- Save the HTML file as MHT with the ConvertHTML method.
The code sample below demonstrates how to convert an HTML file to MHT format programmatically in Java:
Explore Aspose.HTML for Java API
You might visit the API documentation to understand many other features supported by the API.
Get Free License
You can evaluate the API in its full capacity by requesting a free temporary license.
In this article, you have learned how to convert an HTML file to MHT or MHTML file programmatically in Java. Moreover, it also covers the advanced features to customize the conversion process. Please feel free to reach out to us at the forum in case of any inquiries.