Convert PowerPoint to image in Java

By using Spire.Presentation for JAVA, we can easily convert the presentation slides to bitmap and metafile image in JAVA applications. The following sample demonstrate how to convert PowerPoint to image in JAVA. The supported images could be in Jpeg, Jpg, Png, Tiff, and SVG format etc.

Save PowerPoint as BMP Image

By using ISlide.SaveAsImage() method, we could easily convert specific presentation slide to BMP image in Jpg, Png, Tiff, Bmp, here we will use .pptx to .png as example:

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

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

        Presentation ppt = new Presentation();
        ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");
        //Save PPT document to images
        for (int i = 0; i < ppt.getSlides().getCount(); i++) {
            BufferedImage image = ppt.getSlides().get(i).saveAsImage();
            String fileName = String.format("output/ToImage-%d.png", i);
            ImageIO.write(image, "PNG",new File(fileName));
        }
        ppt.dispose();

    }
}

Effective screenshot of the resulted PNG image:

Convert PowerPoint to image in Java

Save PowerPoint to SVG (Scalable Vector Graphics)

By using saveToSVG() method, we could save PowerPoint document to Scalable Vector Graphics easily.

import com.spire.presentation.Presentation;
import java.io.FileOutputStream;
import java.util.ArrayList;

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

        Presentation ppt = new Presentation();
        ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");
        //Save PPT document to images
        ArrayList svgBytes =(ArrayList) ppt.saveToSVG();
        int count = svgBytes.size();
        int len = svgBytes.size();
        for (int i = 0; i < len; i++)
        {
            byte[] bytes = svgBytes.get(i);
            FileOutputStream stream = new FileOutputStream(String.format("output/ToSVG-%d.svg", i));
            stream.write(bytes);
        }
        ppt.dispose();

    }

Convert PowerPoint to image in Java