Save PowerPoint Shapes as Images in Java

This article shows you how to export shapes in a specific slide as images using Spire.Presentation for Java. Below is a screenshot of the sample PowerPoint document.

Save PowerPoint Shapes as Images in Java

import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

public class SaveShapeAsImage {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample PowerPoint file
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\chart and table.pptx");

        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);

        //Declare a BufferedImage variable
        BufferedImage image;

        //Loop through the shapes in the slide
        for (int i = 0; i < slide.getShapes().getCount(); i++) {

            //Save the specific shape as image data
            image = slide.getShapes().saveAsImage(i);

            //Write data to png file
            File file = new File(String.format("ToImage-%d.png", i));
            ImageIO.write(image, "PNG", file);
        }
    }
}

Output

Save PowerPoint Shapes as Images in Java