Apache POI PPT Tutorial
Selected Reading
- Apache POI PPT - Discussion
- Apache POI PPT - Useful Resources
- Apache POI PPT - Quick Guide
- Apache POI PPT - PPT to Image
- Apache POI PPT - Merging
- Apache POI PPT - Formatting Text
- Apache POI PPT - Reading Shapes
- Apache POI PPT - Creating Hyperlinks
- Apache POI PPT - Images
- Apache POI PPT - Slide Management
- Apache POI PPT - Slide Layouts
- Apache POI PPT - Presentation
- Apache POI PPT - Classes & Methods
- Apache POI PPT - Installation
- Apache POI PPT - Java API Flavors
- Apache POI PPT - Overview
- Apache POI PPT - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache POI PPT - PPT to Image
Apache POI PPT - PPT to Image
You can convert a presentation to an image file. The following program shows how to go about it.
import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; 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; import java.util.List; import org.apache.poi.xslf.usermodel.XMLSpdeShow; import org.apache.poi.xslf.usermodel.XSLFSpde; pubpc class PptToImage { pubpc static void main(String args[]) throws IOException { //creating an empty presentation File file=new File("pptToImage.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file)); //getting the dimensions and size of the spde Dimension pgsize = ppt.getPageSize(); List<XSLFSpde> spde = ppt.getSpdes(); BufferedImage img = null; for (int i = 0; i < spde.size(); i++) { 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 spde.get(i).draw(graphics); } //creating an image file as output FileOutputStream out = new FileOutputStream("ppt_image.png"); javax.imageio.ImageIO.write(img, "png", out); ppt.write(out); System.out.println("Image successfully created"); out.close(); } }
Save the above Java code as PpttoPNG.java, and then compile and execute it from the command prompt as follows −
$javac PpttoPNG.java $java PpttoPNG
It will compile and execute to generate the following output −
Image created successfully
The following snapshot shows the presentation that is given as input −

Given below is the snapshot of the image created at the specified location.
