3

Hello I am trying to use the Apache Poi framework to convert each slide of a ppt to an individual png. The problem is that some slides are deformed. For instance there is a slide where the background has a rainbow color to it. And Images that are on some slides do not appear at all on the .png file

here is the code:

        FileInputStream is = new FileInputStream(args[0]);

        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,
        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);

        //save the output
        FileOutputStream out = new FileOutputStream("C:\\Users\\Farzad\\Desktop\\slide-" + (i+1) + ".png");
        javax.imageio.ImageIO.write(img, "png", out);
        out.close();
        }
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Farzad Towhidi
  • 363
  • 2
  • 6
  • 13
  • Could it be that changing `BufferedImage.TYPE_INT_RGB` improves the quality? – Wivani May 27 '11 at 08:26
  • What version of POI are you trying with? PPT rendering is the kind of thing that gets improved over time, so if you've not tried the latest version then it's worth upgrading – Gagravarr Sep 02 '11 at 17:33
  • will any body tell me which jar to be include to run the above code. Coz I am not getting Dimension, Graphics2D classes.. – Panache Jul 10 '12 at 11:53

1 Answers1

1

For this to work we don't have to use:

graphics.setPaint(Color.white);

Instead use :

graphics.setPaint(
    slideShow.getSlides()[0].getBackground().getFill().getForegroundColor()
);
Nippey
  • 4,708
  • 36
  • 44
Ashutosh
  • 11
  • 1