Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.HTML for Java library provides a wide range of MHTML conversions to images, such as JPG, PNG, BMP, TIFF, and GIF. Converting MHTML to any supported image format follows the mandatory steps:
To specify the output image format, use the
ImageSaveOptions class. The ImageSaveOptions(format) constructor initializes the options object with the format specifying. You can set the image format to JPG, PNG, BMP, GIF, or TIFF. The default ImageFormat is PNG.
In this article, you will find information on how to convert an MHTML to PNG using Aspose.HTML for Java and how to apply
ImageSaveOptions. You can easily use Java examples to convert MHTML to PNG, which are detailed here for converting
MHTML to JPG, MHTML to BMP, MHTML to GIF, and MHTML to TIFF. Just set the ImageFormat to ImageSaveOptions!
Let’s walk through the step-by-step instructions for a simple MHTML to PNG conversion scenario:
FileInputStream class to read an MHTML file as a stream of bytes.ImageFormat.Png will be used as default image format.convertMHTML(stream, options, savePath) method of the
Converter class to save MHTML as PNG image. The method takes as parameters stream, options, and savePath and performs the conversion.Using convertMHTML() methods is the most common way to convert MHTML files to other formats. The following Java code snippet shows how to convert MHTML to PNG:
1// Convert MHTML to PNG using Java
2
3// Open an existing MHTML file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht");
5
6// Initialize ImageSaveOptions
7ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Png);
8
9// Call the convertMHTML() method to convert MHTML to PNG
10Converter.convertMHTML(fileInputStream, options, "sample-output.png");You can download the complete examples and data files from GitHub.
Aspose.HTML for Java provides the ability to programmatically convert MHTML to PNG with full control over various conversion options using ImageSaveOptions. This feature allows users to customize the rendering process by setting the image format, page size, margins, compression level, media type, and other parameters.
| Method | Description |
|---|---|
| setCompression(value) | Sets the Tagged Image File Format (TIFF) Compression. By default this property is Compression.LZW. |
| getCss | Gets a CssOptions object which is used for configuration of CSS properties processing. |
| setFormat(value) | Sets ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default this property is ImageFormat.Png. |
| setBackgroundColor(value) | Sets Color which will fill background of every page. Default value is Color.Transparent(Color.getTransparent()). |
| setPageSetup(value) | Gets a page setup object is used for configuration output page-set. |
| setHorizontalResolution(value) | Sets horizontal resolution for output images in pixels per inch. The default value is 300 dpi. |
| setVerticalResolution(value) | Sets vertical resolution for output images in pixels per inch. The default value is 300 dpi. |
| setSmoothingMode(value) | Sets the rendering quality for this image. |
| getText() | Gets a TextOptions object which is used for configuration of text rendering. |
For further information on how to customize the conversion process with ImageSaveOptions you can refer to the Fine-Tuning Converters article.
Aspose.HTML for Java allows converting MHTML to PNG using default or custom save options. The following Java example shows how to use ImageSaveOptions and create a PNG file with custom page-size and background color:
FileInputStream to read the contents of the MHTML file as a stream of bytes.getBackgroundColor() method to set the background color of the image.setAnyPage() method to set the size of the image.stream, options, savePath) method to save MHTML file as a PNG image. The method takes the stream, options, output file path savePath and performs the conversion operation. 1// Convert MHTML to PNG in Java with custom settings
2
3// Open an existing MHTML file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht");
5
6// Initialize the ImageSaveOptions with a custom page-size and background-color
7ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Png);
8PageSetup pageSetup = new PageSetup();
9Page anyPage = new Page();
10anyPage.setSize(
11 new Size(
12 Length.fromPixels(3000),
13 Length.fromPixels(1000)
14 )
15);
16pageSetup.setAnyPage(anyPage);
17options.setPageSetup(pageSetup);
18options.setBackgroundColor(Color.getGreen());
19
20// Call the convertMHTML() method to convert MHTML to PNG
21Converter.convertMHTML(fileInputStream, options, "sample-options.png");Aspose.HTML offers a free online MHTML to PNG Converter that converts MHTML to PNG with high quality, easy and fast. Just upload, convert your files and get the result in a few seconds!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.