MHT files can be used to archive webpages as they include all the images, CSS, JavaScript, and other resources. In certain situations, you may need to convert an MHT file to an image format. Accordingly, this article covers how to convert an MHT or MHTML to an image in JPG or PNG format programmatically in Java.
- MHT to Image Conversion – Java API Installation
- Convert MHT to JPG Image Programmatically in Java
- Convert MHT to PNG Image in Java
MHT to Image Conversion – Java API Installation
Aspose.HTML for Java API is an advanced HTML processing API that can be used to create or manipulate HTML, MHTML, and other popular file formats. Simply access the API by downloading its JAR files from the Downloads section or use the below details in the pom.xml file of your application:
Repository
<repositories>
<repository>
<id>snapshots</id>
<name>repo</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
</repositories>
Dependency
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html</artifactId>
<version>21.12</version>
<classifier>jdk16</classifier>
</dependency>
</dependencies>
Convert MHT or MHTML to JPG Image in Java
You can export an MHT or MHTML webpage to a JPG format image with the following steps:
- Initialize an instance of the ImageSaveOptions class.
- Specify the output format as JPEG or JPG.
- Convert the source MHT or MHTML to a JPG format image using the ConvertMHTML method.
The code snippet below demonstrates how to convert an MHT or MHTML file to a JPG image in Java:
Convert MHT or MHTML to PNG Image Programmatically in Java
You can quickly convert an MHT or MHTML file to a PNG format image by following the steps listed below:
- Instantiate an object of the ImageSaveOptions class.
- Set the output image format as PNG.
- Convert the MHT or MHTML to a PNG image with the ConvertMHTML method.
The following code sample explains how to convert an MHT or MHTML file to an image in PNG format in Java:
Explore Aspose.HTML for Java API
You may visit the documentation section to learn several other features offered by the API.
Get Free License
You can evaluate any of the features offered by the API in its full capacity by getting a free temporary license.
Conclusion
In this article, you have inspected how to convert an MHT or MHTML file to an image in PNG, JPG, or JPEG format using Java. Furthermore, you may raise any of your queries via the forum so that we can assist you effectively.