use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class TestPOIXMLDocument method testOSGIClassLoadingFixed.
@Test
public void testOSGIClassLoadingFixed() throws IOException {
Thread thread = Thread.currentThread();
ClassLoader cl = thread.getContextClassLoader();
InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx");
try {
thread.setContextClassLoader(cl.getParent());
POIXMLTypeLoader.setClassLoader(cl);
XMLSlideShow ppt = new XMLSlideShow(is);
ppt.getSlides().get(0).getShapes();
ppt.close();
} finally {
thread.setContextClassLoader(cl);
POIXMLTypeLoader.setClassLoader(null);
is.close();
}
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project textdb by TextDB.
the class FileExtractorUtils method extractPPTFile.
/**
* Extracts data from PPT/PPTX from using poi.
*
* @param path
* @return
* @throws DataflowException
*/
public static String extractPPTFile(Path path) throws DataflowException {
try (FileInputStream inputStream = new FileInputStream(path.toString());
XMLSlideShow ppt = new XMLSlideShow(inputStream)) {
StringBuffer res = new StringBuffer();
for (XSLFSlide slide : ppt.getSlides()) {
List<XSLFShape> shapes = slide.getShapes();
for (XSLFShape shape : shapes) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
String text = textShape.getText();
res.append(text);
}
}
}
return res.toString();
} catch (IOException e) {
throw new DataflowException(e);
}
}
Aggregations