# Convert HTML to Image in Java

> Convert HTML to Image in Java. Use Java library API to convert HTML files to images.

Source: https://products.aspose.com/slides/java/conversion/html-to-image/
Updated: 2026-07-31



## Convert HTML to Image in Java

[**Aspose.Slides for Java**](/slides/java/) is a presentation processing API that can import `HTML` content and render the resulting slides as image files.

You can import an `HTML` file into a new `Presentation` with `addFromHtml`, render each resulting `ISlide` as an `IImage`, and save the output in an image format such as `PNG`.

## Convert HTML to Image using Java

To convert `HTML` to image files, create a new `Presentation`, remove its default slide, import the source HTML with `addFromHtml`, and render the resulting slides.

### Java code for converting HTML into Image

```java
Presentation presentation = new Presentation();
try {
    presentation.getSlides().removeAt(0);
    try (FileInputStream htmlStream = new FileInputStream("page.html")) {
        presentation.getSlides().addFromHtml(htmlStream);
    }

    for (int slideIndex = 0; slideIndex < presentation.getSlides().size(); slideIndex++) {
        ISlide slide = presentation.getSlides().get_Item(slideIndex);
        IImage slideImage = slide.getImage(1f, 1f);
        try {
            slideImage.save("slide_" + (slideIndex + 1) + ".png", ImageFormat.Png);
        } finally {
            slideImage.dispose();
        }
    }
} finally {
    presentation.dispose();
}
```

## How to convert HTML to Image using Aspose.Slides for Java API

These are the steps to convert HTML to Image in Java.

Install [**Aspose.Slides for Java**](/slides/java/).

Add a library reference (import the library) to your Java project.

Load the source `HTML` file into a `Presentation`.

Render each `ISlide` as an `IImage` and save it as an image file.

## Convert HTML To Other Supported Formats
