Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert MHTML to PNG in Java, open the MHTML source as a file stream, create ImageSaveOptions with ImageFormat.Png, and call
Converter.convertMHTML(). PNG is also the default output format of the parameterless ImageSaveOptions() constructor.
Converting MHTML to PNG produces a static lossless image of archived web content. PNG is a suitable choice for text, diagrams, interface captures, and other output where sharp edges or transparency are more important than the smaller files typically produced by JPG compression.
Follow these steps for a basic MHTML-to-PNG conversion:
FileInputStream.ImageFormat.Png.The following example converts sample.mht to sample-output.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");Download complete Java examples and data files from GitHub.
ImageSaveOptions provides access to image format, page setup, resolution, background color, CSS processing, text rendering, and other output settings. Its default page background is transparent, although backgrounds defined by the archived HTML and CSS can still be rendered.
To convert MHTML to PNG with custom page settings:
ImageSaveOptions with ImageFormat.Png.PageSetup object with the required page dimensions.Converter.convertMHTML().The following example converts sample.mht to sample-options.png, sets a green background, and uses a 3000 × 1000 pixel page.
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");For additional image settings, see Fine-Tuning Converters.
Yes. Use the free online MHTML to PNG Converter for a quick manual conversion. Aspose.HTML for Java is a commercial API for programmatic conversion and can be evaluated before licensing; see Licensing.
PNG supports transparency, and the default page fill in ImageSaveOptions is transparent. However, a background color defined in the archived page or its CSS is still part of the rendered content. Call setBackgroundColor() when you need a specific page background.
Use the free online MHTML to PNG Converter for quick manual conversion without writing Java code.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.