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);
}
}
}
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();
}
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();
}
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);
}
}
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());
}
}
}
}
Aggregations