Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PPTX to PNG image using Apache POI
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Transcoder {
public static void main(String args[]) throws IOException{
//creating an empty presentation
File file=new File("sample-ppt-for-converter.pptx");
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(file));
//getting the dimensions and size of the slide
Dimension pgsize = ppt.getPageSize();
java.util.List<XSLFSlide> slide = ppt.getSlides();
for (int i = 0; i < slide.size(); i++) {
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
//clear the drawing area
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
//render
slide.get(i).draw(graphics);
//creating an image file as output
FileOutputStream out = new FileOutputStream("ppt_image_" + i + ".png");
javax.imageio.ImageIO.write(img, "png", out);
System.out.println("Image successfully created");
out.close();
}
}
}
@jaluDadhich

This comment has been minimized.

Copy link

jaluDadhich commented Jul 30, 2019

Hi
How do you convert the .ppt to image , Please share the answer

@aautar

This comment has been minimized.

Copy link
Owner Author

aautar commented Aug 4, 2019

You can try the code above, but I remember encountering a number of issues with Apache POI rendering slides.. but things may have changed since 2017 🤷‍♂️

We ended up using the Zamzar API (https://developers.zamzar.com/) which worked well for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.