Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert MHTML to JPG in Java, open the MHTML source as a file stream, create ImageSaveOptions with ImageFormat.Jpeg, and call
Converter.convertMHTML(). Use ImageSaveOptions to configure page size, background color, resolution, and rendering options.
Converting MHTML to JPG produces a static raster representation of an archived web page. JPG uses lossy compression and is useful for previews, reports, presentations, and sharing when a smaller output file is more important than transparency or lossless detail.
The shortest example opens an MHTML file and passes its stream, JPEG save options, and the output path directly to Converter.convertMHTML().
1// Convert MHTML to JPG using Java
2
3// Open an existing MHTML file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht");
5
6// Invoke the convertMHTML() method to convert MHTML to JPG
7Converter.convertMHTML(fileInputStream, new ImageSaveOptions(ImageFormat.Jpeg), "convert-by-few-lines.jpg");The sample converts sample.mht and saves the result as convert-by-few-lines.jpg.
Follow these steps for a basic MHTML-to-JPG conversion:
FileInputStream.ImageFormat.Jpeg.Converter.convertMHTML(stream, options, outputPath) to convert MHTML to JPG.The following example converts sample.mht to sample-output.jpg.
1// Convert MHTML to JPG in Java
2
3// Open an existing MHTML file for reading
4java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht");
5
6// Create an instance of the ImageSaveOptions class
7ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg);
8
9// Call the convertMHTML() method to convert MHTML to JPG
10Converter.convertMHTML(fileInputStream, options, "sample-output.jpg");Download complete Java examples and data files from GitHub.
The ImageSaveOptions class controls the image format and rendering settings used during MHTML-to-image conversion.
| Method | Use it to |
|---|---|
setFormat(value) | Select JPG, PNG, BMP, GIF, or TIFF. The default format is PNG. |
setBackgroundColor(value) | Set the color that fills each output page. The default is transparent. |
getPageSetup() | Access the page setup used to configure output page size and margins. |
setHorizontalResolution(value) | Set horizontal resolution in pixels per inch. The default is 300 dpi. |
setVerticalResolution(value) | Set vertical resolution in pixels per inch. The default is 300 dpi. |
setUseAntialiasing(value) | Enable or disable antialiasing. Antialiasing is enabled by default. |
setCompression(value) | Select TIFF compression. The default TIFF compression is LZW. |
getCss() | Access CSS processing options. |
getText() | Access text rendering options. |
To convert MHTML to JPG with custom page settings:
ImageSaveOptions with ImageFormat.Jpeg.PageSetup.Converter.convertMHTML().The following example converts sample.mht to sample-options.jpg, sets a green background, and uses a 1000 × 500 pixel page.
1// Convert MHTML to JPG 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.Jpeg);
8options.setBackgroundColor(Color.getGreen());
9options.getPageSetup().setAnyPage(new Page());
10options.getPageSetup().getAnyPage().setSize(new Size(Length.fromPixels(1000), Length.fromPixels(500)));
11
12// Call the convertMHTML() method to convert MHTML to JPG
13Converter.convertMHTML(fileInputStream, options, "sample-options.jpg");For additional image settings, see Fine-Tuning Converters.
Yes. Use the free online MHTML to JPG 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.
No. MHTML-to-JPG conversion produces static raster image data. Links, form controls, scripts, audio, video, and other interactive behavior are not preserved as interactive features in the JPG output.
Use the free online MHTML to JPG 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.