Convert HTML to JPG in Python

Import HTML content and render it as JPG images with a cross-platform Python API

Convert HTML to JPG using Python

Create a Presentation, remove its default blank slide, import the HTML file, and render each generated Slide as a JPEG image.

Python code for converting HTML into JPG

with slides.Presentation() as presentation:
    presentation.slides.remove_at(0)

    with open("page.html", "rb") as html_stream:
        presentation.slides.add_from_html(html_stream)

    for slide in presentation.slides:
        file_path = "slide_{}.jpg".format(slide.slide_number)
        with slide.get_image() as image:
            image.save(file_path, slides.ImageFormat.JPEG)

Convert HTML to JPG in Python

Aspose.Slides for Python via .NET lets you import HTML content into a presentation and render the resulting slides as JPG images. The API provides SlideCollection.add_from_html for importing HTML and Slide.get_image for rendering each slide.

The example below writes one JPEG file for each slide created from the HTML document. This workflow does not require Microsoft PowerPoint or another presentation application.

How to convert HTML to JPG using Aspose.Slides for Python API

These are the steps to convert HTML to JPG in Python.

  1. Install Aspose.Slides for Python via .NET.
  2. Create a Presentation and remove its default blank slide.
  3. Open the source HTML file and pass its stream to SlideCollection.add_from_html.
  4. Access each imported Slide, call Slide.get_image, and save the result with ImageFormat.JPEG.

Convert HTML to Other Supported Formats

You can also import HTML content and save it in other supported formats.