MHTML to Image Conversion
In this article, you will find information on how to convert an MHTML to Image File Formats such as JPEG, PNG, BMP, TIFF and how to use ImageSaveOptions and MemoryStreamProvider parameters.
The static methods of the Converter class are primarily used as the easiest way to convert MHTML file into various formats. You can convert MHTML to Image in your Java application literally with a single line of code!
Convert MHTML to JPG
You can check the quality of MHTML to JPG conversion at this link: https://products.aspose.app/html/en/conversion/mhtml-to-jpg
The following Java code snippet shows how to convert MHTML to JPG using Aspose.HTML for Java.
- Open an existing MHTML file;
- Create a new ImageSaveOptions object with JPG ImageFormat;
- Use the
Converter.convertMHTML
method of Converter class to save MHTML as a JPG image. You need to pass the MHTML stream, ImageSaveOptions, and output file path to theConverter.convertMHTML
method to convert MHTML to JPG.
Convert MHTML to PNG
The following Java code snippet shows how to convert MHTML to PNG using Aspose.HTML for Java.
- Open an existing MHTML file;
- Create a new ImageSaveOptions object with PNG ImageFormat;
- Use the
Converter.convertMHTML
method of Converter class to save MHTML as a PNG image. You need to pass the MHTML stream, ImageSaveOptions, and output file path to theConverter.convertMHTML
method to convert MHTML to PNG.
Convert MHTML to BMP
You can check the quality of MHTML to BMP conversion at this link: https://products.aspose.app/html/en/conversion/mhtml-to-bmp
The following Java code snippet shows how to convert MHTML to BMP using Aspose.HTML for Java.
- Open an existing MHTML file;
- Create a new ImageSaveOptions object with BMP ImageFormat;
- Use the
Converter.convertMHTML
method of Converter class to save MHTML as a BMP image. You need to pass the MHTML stream, ImageSaveOptions, and output file path to theConverter.convertMHTML
method to convert MHTML to BMP .
Convert MHTML to GIF
The following Java code snippet shows how to convert MHTML to GIF using Aspose.HTML for Java.
- Open an existing MHTML file;
- Create a new ImageSaveOptions object with GIF ImageFormat;
- Use the
Converter.convertMHTML
method of Converter class to save MHTML as a GIF image. You need to pass the MHTML stream, ImageSaveOptions, and output file path to theConverter.convertMHTML
method to convert MHTML to GIF .
Convert MHTML to TIFF
You can check the quality of MHTML to TIFF conversion at this link: https://products.aspose.app/html/en/conversion/mhtml-to-tiff
The following Java code snippet shows how to convert MHTML to TIFF using Aspose.HTML for Java.
- Open an existing MHTML file;
- Create a new ImageSaveOptions object with TIFF ImageFormat;
- Use the
Converter.convertMHTML
method of Converter class to save MHTML as a TIFF image. You need to pass the MHTML stream, ImageSaveOptions, and output file path to theConverter.ConvertMHTML
method to convert MHTML to TIFF.
Save Options
ImageSaveOptions allows you to customize the rendering process. You can specify the image format, page size, margins, compression level, CSS media-type, etc. The following example shows how to use ImageSaveOptions and create the output image with custom page-size and background color:
To learn more about ImageOptions please read Fine-Tuning Converters article.
Output Stream Providers
If it is required to save files in the remote storage (e.g., cloud, database, etc.) you can implement MemoryStreamProvider interface to have manual control over the file creating process. This interface designed as a callback object to create a stream at the beginning of the document/page (depending on the output format) and release the early created stream after rendering document/page.
The example below shows how to implement and use the your own MemoryStreamProvider in the application: