Contact at or 8097636691
Responsive Ads Here

Saturday, 30 June 2018

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 org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class PpttoPNG {
   public static void main(String args[]) throws IOException {
      //creating an empty presentation
      File file = new File("addingimage.pptx");
      XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(file));
      //getting the dimensions and size of the slide 
      Dimension pgsize = ppt.getPageSize();
      XSLFSlide[] slide = ppt.getSlides();
      for (int i = 0; i < slide.length; i++) {
         BufferedImage img = new BufferedImage(
            pgsize.width, pgsize.height,BufferedImage.TYPE_INT_RGB);
         Graphics2D graphics = img.createGraphics();

         //clear the drawing area
         graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

      //creating an image file as output
      FileOutputStream out = new FileOutputStream("ppt_image.png");
      javax.imageio.ImageIO.write(img, "png", out);
      System.out.println("Image successfully created");
Save the above Java code as, and then compile and execute it from the command prompt as follows −
$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.
PPT Image

No comments:

Post a Comment