# Convert HTML to PNG in Python

> Convert HTML content to PNG images in Python. Use the Aspose.Slides Python API to import HTML and render each generated slide as a PNG image.

Source: https://products.aspose.com/slides/python-net/conversion/html-to-png/
Updated: 2026-07-23



## Convert HTML to PNG in Python

[*Aspose.Slides for Python via .NET*](/slides/python-net/) lets you import HTML content into a presentation and render the resulting slides as PNG images. The API provides `SlideCollection.add_from_html` for importing HTML and `Slide.get_image` for rendering each slide.

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

## Convert HTML to PNG using Python

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

### Python code for converting HTML into PNG

```python
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 = f"slide_{slide.slide_number}.png"
        with slide.get_image(1, 1) as slide_image:
            slide_image.save(file_path, slides.ImageFormat.PNG)
```

## How to convert HTML to PNG using Aspose.Slides for Python API

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

Install [*Aspose.Slides for Python via .NET*](/slides/python-net/).

Create a `Presentation` and remove its default blank slide.

Open the source HTML file and pass its stream to `SlideCollection.add_from_html`.

Access each imported `Slide`, call `Slide.get_image`, and save the result with `ImageFormat.PNG`.

## Convert HTML to Other Supported Formats

- [HTML TO IMAGE](/slides/python-net/conversion/html-to-image/)
- [HTML TO JPG](/slides/python-net/conversion/html-to-jpg/)
- [HTML TO PDF](/slides/python-net/conversion/html-to-pdf/)
- [HTML TO TIFF](/slides/python-net/conversion/html-to-tiff/)
- [HTML TO XML](/slides/python-net/conversion/html-to-xml/)
