Search in sources :

Example 26 with XMLSlideShow

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();
    }
}
Also used : InputStream(java.io.InputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) Test(org.junit.Test)

Example 27 with XMLSlideShow

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);
    }
}
Also used : XSLFSlide(org.apache.poi.xslf.usermodel.XSLFSlide) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFTextShape(org.apache.poi.xslf.usermodel.XSLFTextShape) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) XSLFShape(org.apache.poi.xslf.usermodel.XSLFShape) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)27 Test (org.junit.Test)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Metacard (ddf.catalog.data.Metacard)5 XSLFSlide (org.apache.poi.xslf.usermodel.XSLFSlide)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)4 FileOutputStream (java.io.FileOutputStream)3 XSLFShape (org.apache.poi.xslf.usermodel.XSLFShape)3 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 Rectangle2D (java.awt.geom.Rectangle2D)2 File (java.io.File)2 Date (java.util.Date)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)2