A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/convert_slides_into_images.htm below:

How to convert the slides of a PPT into images in Java

How to convert the slides of a PPT into images in Java Problem Description

How to convert the slides of a PPT into images.

Solution

Following is the program to convert the slides of a PPT into images.

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

public class PptToImage {
   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();
      BufferedImage img = null;

      for (int i = 0; i < slide.length; 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
         slide[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();
   }
}
Input Output

java_apache_poi_ppt


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4