Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone have an example of Apache POI converting PPTX to PNG

Does anyone know of a good example of converting a PPTX powerpoint presentation to some form of image? PNG/GIF/etc?

I can do it for a PPT but looking for a PPTX conversion example

Thanks

like image 734
techarch Avatar asked Aug 12 '10 19:08

techarch


3 Answers

In the meantime it works (... copied it from there):

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class PptToPng {
    public static void main(String[] args) throws Exception {
        FileInputStream is = new FileInputStream("example.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        is.close();

        double zoom = 2; // magnify it by 2
        AffineTransform at = new AffineTransform();
        at.setToScale(zoom, zoom);

        Dimension pgsize = ppt.getPageSize();

        XSLFSlide[] slide = ppt.getSlides();
        for (int i = 0; i < slide.length; i++) {
            BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            graphics.setTransform(at);

            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            slide[i].draw(graphics);
            FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }
    }
}
like image 187
kiwiwings Avatar answered Nov 20 '22 22:11

kiwiwings


Answering my own question, I subscribed to the development mailing list and asked this question.

The answer is that this functionailty is currently not supported by apache poi

like image 33
techarch Avatar answered Nov 20 '22 22:11

techarch


There's an example class PPTX2PNG now bundled with POI that seems to work with decent results for the PPTX decks I've thrown at it:

http://svn.apache.org/repos/asf/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java

like image 40
user1454265 Avatar answered Nov 20 '22 22:11

user1454265