When I feed the ppt file (as attached file) to the example in the POI home page -> HSLF -> Shapes How to -> Export PowerPoint slides into java.awt.Graphics2D Exception in thread "main" java.lang.NullPointerException at org.apache.poi.hslf.model.Picture.draw(Picture.java:266) at org.apache.poi.hslf.model.ShapeGroup.draw(ShapeGroup.java:280) at org.apache.poi.hslf.model.Slide.draw(Slide.java:431) at test.TestShape.exportToImage(TestShape.java:135) at test.TestShape.main(TestShape.java:112) I know the problem is the in Picture's draw function the getPictureData is null. But why? HSLF provides a way to export slides into images. You can capture slides into java.awt.Graphics2D object (or any other) and serialize it into a PNG or JPEG format. Please note, although HSLF attempts to render slides as close to PowerPoint as possible, the output may look differently from PowerPoint due to the following reasons: * Java2D renders fonts differently vs PowerPoint. There are always some differences in the way the font glyphs are painted * HSLF uses java.awt.font.LineBreakMeasurer to break text into lines. PowerPoint may do it in a different way. * If a font from the presentation is not avaiable, then the JDK default font will be used. Current Limitations: * Some types of shapes are not yet supported (WordArt, complex auto-shapes) * Only Bitmap images (PNG, JPEG, DIB) can be rendered in Java FileInputStream is = new FileInputStream("slideshow.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, 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("slide-" + (i+1) + ".png"); javax.imageio.ImageIO.write(img, "png", out); out.close(); }
Please try the latest svn version. Daily builds are available at http://encore.torchbox.com/poi-svn-build/ Yegor
Attachment missing and no user feedback for ages ... closing this for now.