Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Converting the Slides of a PPT into Images using Java

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

To convert PowerPoint slides to images, multiple packages are required like, java.awt because It contains all the classes for creating user interfaces and for painting graphics and images, because It provides a set of input streams and a set of output streams used to read and write data to files or other input and output sources, Apache POI because It is used to create, modify, and display Microsoft Office files using Java programs.

Download Apache POI 

  1. Download the zip file from the official site.
  2. Extract the external jar files from the zip file.
  3. Add the external jar files. 
    For that select Java Build Path -> Configure Build Path -> Libraries -> Class -> Add External Jars…
  4. Select the jar file from the required folder
  5. Click Apply and close.

Imports from java.awt

  1. java.awt.Color: This class has the colors needed to change the appearance of objects in the interface.
  2. java.awt.Dimension It contains the height and width of a component.
  3. java.awt.Graphics2D It provides provides control over geometry, coordinate transformations, color management, and text layout.
  4. java.awt.geom.Rectangle2D It describes a rectangle defined by a location (x,y) and dimension (w x h) .
  5. java.awt.image.BufferedImage It is used to handle and manipulate the image data.

Imports from 

  1. It contains several methods for working with the path name, deleting and renaming files,etc.
  2. It is used to read data from a file.
  3. It is used for writing data to a File.
  4. It is an exception which is used in the code to throw a failure in Input and Output operations

Imports from Apache POI 

  1. org.apache.poi.xslf.usermodel.XMLSlideShow: It is used to create objects to read or write a slideshow.
  2. org.apache.poi.xslf.usermodel.XSLFSlide: It is used to create and manage a slide in a presentation.



// Converting the slides of a PPT into Images using Java
import java.util.List;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
public class PPTToImages {
    public static void main(String args[])
        throws IOException
        // create an empty presentation
        File file = new File("slides.pptx");
        XMLSlideShow ppt
            = new XMLSlideShow(new FileInputStream(file));
        // get the dimension and size of the slide
        Dimension pgsize = ppt.getPageSize();
        List<XSLFSlide> slide = ppt.getSlides();
        BufferedImage img = null;
        for (int i = 0; i < slide.size(); i++) {
            img = new BufferedImage(
                pgsize.width, pgsize.height,
            Graphics2D graphics = img.createGraphics();
            // clear area
            graphics.fill(new Rectangle2D.Float(
                0, 0, pgsize.width, pgsize.height));
            // draw the images
            FileOutputStream out = new FileOutputStream(
                "ppt_image" + i + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
        System.out.println("Image successfully created");

Before the execution of the program:


After Execution of the program:



My Personal Notes arrow_drop_up
Last Updated : 15 Jul, 2021
Like Article
Save Article
Similar Reads
Related Tutorials