Bug 57442 - Error on Extracting pptx slides to png
Summary: Error on Extracting pptx slides to png
Status: RESOLVED LATER
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-14 08:41 UTC by Dondell Batac
Modified: 2015-08-05 23:30 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dondell Batac 2015-01-14 08:41:49 UTC
Hi,

Can somebody help me out. I am a new user of POI and I am using it to extract pptx slides to PNG images, but something went wrong in one of my .pptx file that says Nullpointer. Below is the snippet of the code and full stacktrace.

String path = "D:\\GDrive\\Projects\\BWServer\\BWServer\\src\\powerpoint_recieved";
        FileInputStream is = new FileInputStream(path + "\\snbu-20120924rev.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        is.close();

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

        Dimension pgsize = ppt.getPageSize();
        XSLFSlide[] slide = ppt.getSlides();
        int slideSize = slide.length;
        for (int i = 0; i < slideSize; i++) {
            System.out.println("slide-" + (i + 1));
            System.out.println("" + slide[i].getTitle());

            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);
            //clear the drawing area
            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            // render
            try {
                // draw stuff
                slide[i].draw(graphics);
            } catch (NullPointerException ex) {
                ex.printStackTrace();
            }

            FileOutputStream out = new FileOutputStream(path + "\\sample\\slide-" + (i + 1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();

            StringBuilder strNotesBuild = new StringBuilder();
            try {
                XSLFNotes mynotes = slide[i].getNotes();
                for (XSLFShape shape : mynotes) {
                    if (shape instanceof XSLFTextShape) {
                        XSLFTextShape txShape = (XSLFTextShape) shape;
                        for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
                            if (SlideNotesUtil.isString(xslfParagraph.getText()) == true) {
//                                System.out.println("Slide " + (i + 1) + " Notes: " + xslfParagraph.getText());
                                strNotesBuild.append(xslfParagraph.getText()).append("\n");
                            }
                        }
                        FileUtil.writeSlideNotesFile(path + "\\sample\\slide-" + (i + 1) + ".txt", strNotesBuild);
                    }
                }
            } catch (Exception e) {
            }
        }

OUTPUT:

java.lang.NullPointerException
	at org.apache.poi.xslf.usermodel.XSLFPictureShape.getBlipId(XSLFPictureShape.java:118)
	at org.apache.poi.xslf.usermodel.XSLFPictureShape.getPictureData(XSLFPictureShape.java:99)
	at org.apache.poi.xslf.usermodel.XSLFPictureShape.drawContent(XSLFPictureShape.java:124)
	at org.apache.poi.xslf.usermodel.RenderableShape.render(RenderableShape.java:540)
	at org.apache.poi.xslf.usermodel.XSLFSimpleShape.draw(XSLFSimpleShape.java:534)
	at org.apache.poi.xslf.usermodel.XSLFSheet.draw(XSLFSheet.java:506)
	at org.apache.poi.xslf.usermodel.XSLFSheet.draw(XSLFSheet.java:490)
	at org.apache.poi.xslf.usermodel.XSLFSheet.draw(XSLFSheet.java:490)
	at org.apache.poi.xslf.usermodel.XSLFSlide.draw(XSLFSlide.java:220)
	at ppttopng.PptToPng.main(PptToPng.java:55)
Comment 1 Dominik Stadler 2015-03-01 17:50:43 UTC
Can you provide a sample file which shows this problem?
Comment 2 Andreas Beeker 2015-08-05 23:30:31 UTC
Closing this for now, as we haven't received the file causing this issue.
Please reopen when you have uploaded the file.