Search in sources :

Example 6 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class XSLFTestDataSamples method writeOutAndReadBack.

public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
    try {
        doc.write(baos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    InputStream bais;
    bais = new ByteArrayInputStream(baos.toByteArray());
    try {
        return new XMLSlideShow(OPCPackage.open(bais));
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            baos.close();
            bais.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class TestXSLFPowerPointExtractor method testTable.

@Test
public void testTable() throws Exception {
    XMLSlideShow xml = openPPTX("present1.pptx");
    XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
    String text = extractor.getText();
    assertTrue(text.length() > 0);
    // Check comments are there
    assertContains(text, "TEST");
    extractor.close();
    xml.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) Test(org.junit.Test)

Example 8 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class TestXSLFPowerPointExtractor method testGetMasterText.

public void testGetMasterText() throws Exception {
    XMLSlideShow xml = openPPTX("WithMaster.pptx");
    XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
    extractor.setSlidesByDefault(true);
    extractor.setNotesByDefault(false);
    extractor.setMasterByDefault(true);
    String text = extractor.getText();
    assertTrue(text.length() > 0);
    // Check master text is there
    assertContains(text, "Footer from the master slide");
    // Theme text shouldn't show up
    // String themeText =
    //     "Theme Master Title\n" +
    //     "Theme Master first level\n" +
    //     "And the 2nd level\n" +
    //     "Our 3rd level goes here\n" +
    //     "And onto the 4th, such fun....\n" +
    //     "Finally is the Fifth level\n";
    // Check the whole text
    String wholeText = "First page title\n" + "First page subtitle\n" + "This is the Master Title\n" + "This text comes from the Master Slide\n" + "\n" + // TODO Detect we didn't have a title, and include the master one
    "2nd page subtitle\n" + "Footer from the master slide\n" + "This is the Master Title\n" + "This text comes from the Master Slide\n";
    assertEquals(wholeText, text);
    extractor.close();
    xml.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow)

Example 9 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project ddf by codice.

the class PptxInputTransformer method extractThumbnail.

/**
     * SlideShowFactory.create() will perform the tests for password protected files.
     * <p/>
     * Because Apache POI dynamically loads the classes needed to handle a PPTX file, the default
     * class loader is unable to find the dependencies during runtime. Therefore, the original class
     * loader is saved, then current class loader is set to this class's class loader, and finally
     * the original class loader is restored.
     *
     * @param metacard
     * @param input
     * @throws IOException
     */
private void extractThumbnail(Metacard metacard, InputStream input) throws IOException {
    ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        SlideShow<?, ?> genericSlideShow = SlideShowFactory.create(input);
        if (genericSlideShow instanceof XMLSlideShow) {
            XMLSlideShow xmlSlideShow = (XMLSlideShow) genericSlideShow;
            byte[] thumbnail = generatePptxThumbnail(xmlSlideShow);
            if (thumbnail != null) {
                metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, thumbnail));
            }
        } else {
            LOGGER.debug("Cannot transform old style (OLE2) ppt : id = {}", metacard.getId());
        }
    } finally {
        Thread.currentThread().setContextClassLoader(originalContextClassLoader);
    }
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 10 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project ddf by codice.

the class PptxInputTransformerTest method testTitleAsMetadataTitle.

@Test
public void testTitleAsMetadataTitle() throws IOException, CatalogTransformerException, InterruptedException {
    try (XMLSlideShow ss = new XMLSlideShow()) {
        ss.createSlide();
        ss.getProperties().getCoreProperties().setTitle("TheTitle");
        try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
            ss.write(os);
            try (ByteArrayInputStream inStr = new ByteArrayInputStream(os.toByteArray())) {
                PptxInputTransformer t = new PptxInputTransformer(inputTransformer, false);
                Metacard m = t.transform(inStr);
                assertThat(m.getTitle(), nullValue());
            }
        }
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)25 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)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)3 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 Rectangle2D (java.awt.geom.Rectangle2D)2 FileOutputStream (java.io.FileOutputStream)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 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 XSLFShape (org.apache.poi.xslf.usermodel.XSLFShape)2