https://issues.apache.org/bugzilla/show_bug.cgi?id=57442
Bug ID: 57442
Summary: Error on Extracting pptx slides to png
Product: POI
Version: 3.10-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XSLF
Assignee: [email protected]
Reporter: [email protected]
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)
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]