Convert an Archived Web Page to JPEG
Aspose.HTML for Python via .NET
converts MHTML or MHT archives to JPEG with
Converter.convert_mhtml()
and
ImageSaveOptions
. Open the archive as a binary stream, select ImageFormat.JPEG, and write the raster result.
JPEG is an opaque, lossy image format. It is suitable for photographic content and compact previews, but PNG is usually a better choice for transparency, small text, diagrams, and sharp interface graphics.
Convert MHTML to JPEG and View the Python Code
Choose an MHTML or MHT file and keep JPEG selected. The widget creates JPEG output and provides Python code for the same stream-based conversion.
{{#if_output 'PDF' 'DOCX' 'XPS'}}
import aspose.html.converters as conv
import aspose.html.saving as sav
{{/if_output}}
{{#if_output 'BMP' 'JPEG' 'GIF' 'PNG' 'TIFF'}}
import aspose.html.converters as conv
import aspose.html.rendering.image as rim
import aspose.html.saving as sav
{{/if_output}}
with open("{{input lower}}", "rb") as stream:
{{#if_output 'PDF'}}
options = sav.PdfSaveOptions()
{{/if_output}}
{{#if_output 'DOCX'}}
options = sav.DocSaveOptions()
{{/if_output}}
{{#if_output 'XPS'}}
options = sav.XpsSaveOptions()
{{/if_output}}
{{#if_output 'BMP' 'JPEG' 'GIF' 'PNG' 'TIFF'}}
options = sav.ImageSaveOptions(rim.ImageFormat.{{output param2 upper}})
{{/if_output}}
conv.Converter.convert_mhtml(stream, options, "output.{{output lower}}")
The example opens input.mhtml as a binary stream, selects JPEG explicitly, and writes output.jpeg. Set page dimensions, resolution, and a background color when the target system requires a specific image size and appearance.
Python Code to Convert MHTML to JPEG
import aspose.html.converters as conv
import aspose.html.rendering.image as rim
import aspose.html.saving as sav
with open("input.mhtml", "rb") as stream:
options = sav.ImageSaveOptions(rim.ImageFormat.JPEG)
conv.Converter.convert_mhtml(stream, options, "output.jpeg")
How to Convert MHTML to JPEG in Python
- Install the
aspose-html-netpackage. - Open the MHTML or MHT file as a binary stream.
- Create
ImageSaveOptionswithImageFormat.JPEG. - Configure page size, resolution, background color, CSS processing, or smoothing when required.
- Call
Converter.convert_mhtml()with the stream, options, and JPEG path. - Close the input stream. The
withstatement handles this automatically.
Set JPEG Dimensions, Background, and Resources
Use ImageSaveOptions to control how the archived page becomes an opaque raster image:
- Page size: Set the rendered canvas dimensions for the intended preview, attachment, or image-processing workflow.
- Resolution: Increase horizontal and vertical resolution when the destination needs more pixels, while accounting for the resulting file size.
- Background: Set an explicit background color when the source uses transparency because JPEG cannot store transparent pixels.
- CSS and fonts: Apply the required supported styles and make the expected fonts available during conversion.
- Archived resources: Confirm that required images and styles are stored in the archive or accessible from any external locations it references.
See
Convert MHTML to JPG in Python
and the
ImageSaveOptions API Reference
for available image settings.
Install Aspose.HTML for Python via .NET
Install the aspose-html-net package from
PyPI
.
Command
pip install aspose-html-netReview the installation guide and system requirements before deployment. Request a temporary license to test the API without evaluation limitations.
MHTML to JPEG FAQ
1. Can MHTML to JPEG conversion preserve transparent areas?
No. JPEG does not support transparency. Set a suitable background color before conversion when transparent or partially transparent page areas must have a predictable appearance.
2. Why can text and thin lines look less sharp in JPEG than in PNG?
JPEG uses lossy compression, which can introduce visible artifacts around text, diagrams, and interface graphics. Use PNG when sharp edges and lossless output are more important than the typical JPEG use case.
3. Can one MHTML file produce several JPEG images?
Yes. Image output is page based. If the laid-out archive spans several rendered pages, the converter can write separate numbered images rather than placing every page into one JPEG.
4. Can JPEG quality be configured when converting MHTML with ImageSaveOptions?
The current ImageSaveOptions documentation does not expose a separate JPEG quality property. It provides resolution, page setup, background, antialiasing, and text-rendering settings; the compression property applies to TIFF output, not JPEG.
MHTML and Image Conversion Guides
Choose another MHTML result or convert a different source to a raster image.