Bug 46159 - Using the "Shapes How to" Sample to export the slide into images, NullPointException
Summary: Using the "Shapes How to" Sample to export the slide into images, NullPointEx...
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2008-11-06 06:00 UTC by Jie Han
Modified: 2014-12-12 01:21 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Jie Han 2008-11-06 06:00:28 UTC
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);
        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.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));


            //save the output
            FileOutputStream out = new FileOutputStream("slide-"  + (i+1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
Comment 1 Yegor Kozlov 2008-11-16 05:35:53 UTC
Please try the latest svn version. 
Daily builds are available at http://encore.torchbox.com/poi-svn-build/

Comment 2 Andreas Beeker 2014-12-12 01:21:26 UTC
Attachment missing and no user feedback for ages ... closing this for now.