Save Chart, Table and Shape on Presentation slides as Image in Java

Spire.Presentation for Java supports to save the whole presentation slides with table, chart and shape to image. And it also supports to save the single element in the presentation slides, such as chart, table and shape into image. This article will show you how to save shape and chart on Presentation Slide as image in Java.

import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public class ShapeAsImage {
    public static void main(String[] args) throws Exception {
        String inputFile = "Sample.pptx";
        String outputFile = "output/";

        //Create a Presentation instance and load sample file
        Presentation presentation = new Presentation();
        presentation.loadFromFile(inputFile);

        //Traverse every slides and every shapes on the slides
        int k = 0;
        for (int i = 0; i < presentation.getSlides().getCount(); i++) {
            ISlide slide = presentation.getSlides().get(i);
            for (int j = 0; j < slide.getShapes().getCount(); j++) {
                String fileName = outputFile + String.format("shapeToImage-%1$s.png", k);
                //Save every single shape as image
                BufferedImage image = slide.getShapes().saveAsImage(j);
                ImageIO.write(image, "PNG", new File(fileName));
                k++;
            }
        }
    }
}

Save Chart, Table and Shape on Presentation slides as Image in Java

Save Chart, Table and Shape on Presentation slides as Image in Java

Save Chart, Table and Shape on Presentation slides as Image in Java