3

Is there a way to programmatically split slides into .png files using Java? I've searched around and most of the answers given were either in C# or the programs mentioned were not open source

David Weiser
  • 5,190
  • 4
  • 28
  • 35
twidizle
  • 1,495
  • 2
  • 13
  • 16
  • Related: http://stackoverflow.com/questions/3471472 and http://stackoverflow.com/questions/1475849 – finnw Jan 17 '11 at 22:46
  • I have not done this myself, so I won't post this as answer, but you should look at this: http://groups.google.com/group/jodconverter/browse_thread/thread/81ca5ba47d064fcd/a896b5ffe09873ea – Anders Jan 17 '11 at 22:52
  • I removed the 'unix' tag because it was not relevant to this question. – David Weiser Jan 17 '11 at 23:04
  • @David the unix tag could very well be relevant, as if this needs to work on unix then it can't involve a java library that wraps Powerpoint itself. – Peter Recore Jan 17 '11 at 23:06
  • @Peter: there is nothing in the question which is specific to unix. This question, IMO, could apply to any system which runs PowerPoint and Java. – David Weiser Jan 17 '11 at 23:11
  • @David - As it stands the question is vague. there is nothing in the question that says the host running this java code can also run Powerpoint.exe Obviously the question needs some clarification. To me, when the unix tag was there it implied that the solution needs to work on a unix machine, and thus work on a machine without powerpoint. – Peter Recore Jan 18 '11 at 04:36
  • http://stackoverflow.com/questions/18433059/writing-custom-code-for-powerpoint# Any idea – HIRA THAKUR Aug 28 '13 at 10:48

3 Answers3

4

For decent quality, use following code with Apache POI HSLF library (http://poi.apache.org/slideshow/how-to-shapes.html):

        FileInputStream is = new FileInputStream("path_to_your.ppt");
    SlideShow ppt = new SlideShow(is);
    is.close();

    Dimension pgsize = ppt.getPageSize();

    Slide[] slide = ppt.getSlides();
    for (int i = 0; i < slide.length; i++) {

        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, 1);

        Graphics2D graphics = img.createGraphics();
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);

        graphics.setColor(Color.white);
        graphics.clearRect(0, 0, pgsize.width, pgsize.height);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

        // render
        slide[i].draw(graphics);

        // save the output
        FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
        javax.imageio.ImageIO.write(img, "png", out);
        out.close();
    }
Bas
  • 435
  • 4
  • 11
2

You're going to need to use a Java/COM bridge like j-interop (http://www.j-interop.org/) to programmatically control a PowerPoint process and then probably print the individual pages to files. You may be better off just writing a VBA script.

Alex Godofsky
  • 708
  • 4
  • 16
0

use following code with Apache POI library

    FileInputStream is = new FileInputStream("D:\\PPT sample.ppt");
    XMLSlideShow ppt = new XMLSlideShow(is);
    is.close();

    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.SCALE_SMOOTH);
        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);

        //save the output
        FileOutputStream out = new FileOutputStream("D:\\slide-"  + (i+1) + ".JPG");
        javax.imageio.ImageIO.write(img, "JPG", out);
        out.close();