Convert HTML to Image in Java

Convert HTML files to image files using Aspose.Slides for Java without Microsoft PowerPoint.

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

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();
}

Convert HTML to Image in Java

Aspose.Slides for 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.

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

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

  1. Install Aspose.Slides for Java.
  2. Add a library reference (import the library) to your Java project.
  3. Load the source HTML file into a Presentation.
  4. Render each ISlide as an IImage and save it as an image file.

Built with Aspose.Slides

Convert HTML to Image Online

The free Aspose.Slides Conversion app is built with Aspose.Slides for Java, the same API as the code above. Open it and see what the API can do with your own HTML files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides converts files before you write code.
  • Upload HTML files and save them as Image.
  • Download the result or convert more files.

Convert HTML To Other Supported Formats

You can also convert HTML and save it to other file formats.