Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert HTML to JPEG in Python, call Converter.convert_html() with an HTML source, ImageSaveOptions initialized for JPEG, and an output path. The source can be an HTML file, an HTMLDocument, inline HTML with a base URI, or a webpage URL supported by the selected overload.
JPEG and JPG are names for the same lossy image format. JPEG is widely supported and can produce smaller files than PNG, making it useful for webpage previews, reports, and content dominated by photographs. It does not support transparency and may introduce compression artifacts around small text and sharp edges.
The basic workflow explicitly selects JPEG because PNG is the default format of ImageSaveOptions:
ImageSaveOptions with ImageFormat.JPEG.Converter.convert_html() with the source, options, and output JPEG path. 1# Convert HTML to JPEG in Python
2
3import aspose.html as ah
4import aspose.html.converters as conv
5import aspose.html.saving as sav
6import aspose.html.rendering.image as rim
7
8# Load the HTML document
9with ah.HTMLDocument("document.html") as document:
10
11 # Configure JPEG output
12 options = sav.ImageSaveOptions(rim.ImageFormat.JPEG)
13
14 # Convert HTML to JPEG
15 conv.Converter.convert_html(document, options, "output.jpeg")The example loads document.html, selects JPEG output, and writes output.jpeg.
Use a Url object to render an online HTML page as JPEG:
Url object for the webpage.Converter.convert_html(). 1import os
2import aspose.html as ah
3import aspose.html.converters as conv
4import aspose.html.rendering.image as rim
5import aspose.html.saving as sav
6
7output_dir = "output"
8os.makedirs(output_dir, exist_ok=True)
9
10url = ah.Url("https://docs.aspose.com/html/files/aspose.html")
11output_path = os.path.join(output_dir, "aspose-from-url.jpg")
12
13options = sav.ImageSaveOptions(rim.ImageFormat.JPEG)
14conv.Converter.convert_html(url, options, output_path)The application must have network access to the page and its linked resources. A complex website can take longer to process while external resources are loaded.
Use ImageSaveOptions to control the page layout, background, CSS media type, antialiasing, and text hinting:
HTMLDocument.ImageSaveOptions for JPEG and configure the required rendering settings. 1import os
2import aspose.html as ah
3import aspose.html.converters as conv
4import aspose.html.drawing as dr
5import aspose.html.rendering.image as rim
6import aspose.html.saving as sav
7import aspose.pydrawing as pd
8
9input_dir = "data"
10output_dir = "output"
11os.makedirs(output_dir, exist_ok=True)
12
13input_path = os.path.join(input_dir, "document.html")
14output_path = os.path.join(output_dir, "document-options.jpg")
15
16with ah.HTMLDocument(input_path) as document:
17 options = sav.ImageSaveOptions(rim.ImageFormat.JPEG)
18 options.page_setup.any_page = dr.Page(
19 dr.Size(600, 500),
20 dr.Margin(10, 10, 10, 10)
21 )
22 options.background_color = pd.Color.bisque
23 options.use_antialiasing = True
24 options.text.use_hinting = True
25 options.css.media_type = options.css.media_type.SCREEN
26
27 conv.Converter.convert_html(document, options, output_path)The example creates a 600 × 500 pixel page with 10-pixel margins, uses a solid background because JPEG has no alpha channel, and explicitly applies screen-media CSS. Antialiasing is enabled by default; the assignment makes the selected rendering behavior visible in the example.
JPEG is suitable for photographs and continuous-tone images, but its lossy compression can soften text and sharp edges. ImageSaveOptions does not expose a separate JPEG compression-quality property.
page_setup.any_page.size in pixels when exact JPEG dimensions are required.background_color because JPEG cannot store transparency.For shared page, resolution, CSS, and rasterization settings, see Configure Image Output with ImageSaveOptions.
| Problem | Check or fix |
|---|---|
| The output has an unexpected background | JPEG cannot store transparency. Set background_color explicitly. |
| Text or sharp edges look blurred | Increase the actual output pixel dimensions, keep antialiasing enabled, and test font hinting. JPEG compression may still soften sharp edges. |
| A JPEG quality setting cannot be found | ImageSaveOptions does not provide a separate JPEG compression-quality property. Its compression property is for TIFF output. |
For pagination, page sizing, missing resources, and URL-loading problems, see Common HTML to Image Conversion Issues.
Yes. .jpg and .jpeg are file extensions for the same JPEG image format. Use ImageFormat.JPEG with either extension.
No separate JPEG compression-quality property is exposed by ImageSaveOptions. Configure the rendered dimensions, antialiasing, text hinting, background, fonts, and source images to control the visible result.
Yes. Use the Converter.convert_html() overload that accepts the HTML string, a base URI, JPEG save options, and an output path. The base URI is required when the string contains relative resource URLs.
Use the free online HTML to JPG Converter below for occasional manual conversions. For programmatic conversion, you can evaluate the library without a license or follow the licensing guide to request a temporary license.
Use the free online HTML to JPG Converter for quick manual conversion without writing code. Use Aspose.HTML for Python via .NET when HTML-to-JPEG conversion must run in a Python application, service, or document-processing workflow.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.