In this question someone had a similar problem I have: I want to read the content of a .pptx file (only the text), but only got it work with .ppt files. So I tried to solve it with the accepted answer, but I got this exception: java.lang.ClassNotFoundException: org.apache.poi.hslf.model.TextPainter$Key
I used the example from this page (which was suggested in the accepted answer) so I have no idea why it does not work. My code:
public static String readPPTX(String path) throws FileNotFoundException, IOException{
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(path));
String content = "";
XSLFSlide[] slides = ppt.getSlides();
for (XSLFSlide slide : slides){
XSLFShape[] sh = slide.getShapes();
for (int j = 0; j < sh.length; j++){
if (sh[j] instanceof XSLFTextShape){
XSLFTextShape shape = (XSLFTextShape)sh[j];
content += shape.getText() + "\n";
}
}
}
return content;
}
Solution to this issue is to add the poi-scratchpad-3.9.jar file to the classpath of the project.