Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Converting MHTML to PNG can be helpful in saving the visual representation of web content in an image format. PNG, known for its lossless compression, produces high-quality images without any data loss, making it ideal for archiving, sharing, or embedding web content in other documents or presentations. With Aspose.HTML for Python via .NET, you can convert MHTML to PNG programmatically with full control over a wide range of conversion parameters.
In this article, you find information on how to convert MHTML to PNG by using convert_mhtml() methods of the Converter class, and how to apply ImageSaveOptions.
You can check the Aspose.HTML API functionality and convert MHTML in real-time. Load an MHTML file from your local file system, select the output format and run the example. The conversion will be performed with default save options. You will immediately receive the result as a separate file.
To convert MHTML to PNG with ImageSaveOptions specifying, you should follow a few steps:
format property is PNG. Here, you can set the required save options, such as page setup, resolution, etc.The following Python code snippet shows how to convert MHTML to PNG using custom ImageSaveOptions:
1# Convert MHTML to PNG using Python with custom settings
2
3import os
4import aspose.html.converters as conv
5import aspose.html.saving as sav
6import aspose.html.drawing as dr
7
8# Setup directories and define paths
9output_dir = "output/"
10input_dir = "data/"
11os.makedirs(output_dir, exist_ok=True)
12
13document_path = os.path.join(input_dir, "document.mht")
14save_path = os.path.join(output_dir, "mhtml-to-image.png")
15
16# Open an existing MHTML file for reading
17with open(document_path, "rb") as stream:
18
19 # Create an instance of ImageSaveOptions
20 options = sav.ImageSaveOptions()
21 options.page_setup.any_page = dr.Page(dr.Size(800, 600), dr.Margin(40, 40, 10, 10))
22 options.css.media_type.PRINT
23
24 # Convert MHTML to PNG
25 conv.Converter.convert_mhtml(stream, options, save_path)In the example, we use:
page_setup property to specify the page size and margins (top, bottom, left, right);css.media_type property to specify how CSS media queries are handled during the conversion process.Aspose.HTML for Python via .NET allows converting MHTML to Image using default or custom save options. Here is a description of each ImageSaveOptions property:
CssOptions, allows configuring how CSS properties are processed during the HTML to image conversion.Aspose.HTML for Python via .NET supports converting MHTML to PNG, JPG, JPEG, BMP, TIFF, and GIF images. You can use the above Python code for this; to set the output image format, you only need to specify the required extension (format) in the output file name and set the format property for the save options object.
For example, to convert MHTML to GIF, you need:
options = sav.ImageSaveOptions(rim.ImageFormat.GIF);.gif in the output image file name: save_path = os.path.join(output_dir, "mhtml-to-image.gif").Download the Aspose.HTML for Python via .NET library to successfully, quickly, and easily convert your HTML, MHTML, EPUB, SVG, and Markdown documents to the most popular formats.
Visit the Convert HTML to PNG article to learn how to convert HTML to PNG programmatically using the Python library and explore HTML to PNG conversion scenarios with Python examples.
Aspose.HTML offers a free online MHTML to PNG Converter that converts MHTML to PNG image with high quality, easy and fast. Just upload, convert your files and get results in a few seconds!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.