use of org.apache.poi.xslf.usermodel.XMLSlideShow in project textdb by TextDB.
the class FileSourcePptPdfTest method createPPT.
private static void createPPT(String path) throws IOException {
// creating a new empty slide show
XMLSlideShow ppt = new XMLSlideShow();
// creating an FileOutputStream object
File file = new File(path);
FileOutputStream out = new FileOutputStream(file);
// saving the changes to a file
ppt.write(out);
out.close();
ppt.close();
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project bigbluebutton by bigbluebutton.
the class OfficeDocumentValidator method isValid.
public boolean isValid(UploadedPresentation pres) {
boolean valid = true;
if (FilenameUtils.isExtension(pres.getUploadedFile().getName(), FileTypeConstants.PPTX)) {
XMLSlideShow xmlSlideShow;
try {
xmlSlideShow = new XMLSlideShow(new FileInputStream(pres.getUploadedFile()));
valid &= !embedsEmf(xmlSlideShow);
valid &= !containsTinyTileBackground(xmlSlideShow);
// Close the resource once we finished reading it
xmlSlideShow.close();
} catch (IOException e) {
log.error("Cannot open PPTX file " + pres.getName());
valid = false;
}
}
return valid;
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class TestXSLFPowerPointExtractor method testGetSimpleText.
/**
* Get text out of the simple file
* @throws XmlException
* @throws OpenXML4JException
*/
@Test
public void testGetSimpleText() throws IOException, XmlException, OpenXML4JException {
XMLSlideShow xmlA = openPPTX("sample.pptx");
@SuppressWarnings("resource") OPCPackage pkg = xmlA.getPackage();
new XSLFPowerPointExtractor(xmlA).close();
new XSLFPowerPointExtractor(pkg).close();
XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xmlA);
extractor.getText();
String text = extractor.getText();
assertTrue(text.length() > 0);
// Check Basics
assertStartsWith(text, "Lorem ipsum dolor sit amet\n");
assertContains(text, "amet\n\n");
// Our placeholder master text
// This shouldn't show up in the output
// String masterText =
// "Click to edit Master title style\n" +
// "Click to edit Master subtitle style\n" +
// "\n\n\n\n\n\n" +
// "Click to edit Master title style\n" +
// "Click to edit Master text styles\n" +
// "Second level\n" +
// "Third level\n" +
// "Fourth level\n" +
// "Fifth level\n";
// Just slides, no notes
text = extractor.getText(true, false, false);
String slideText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n";
assertEquals(slideText, text);
// Just notes, no slides
text = extractor.getText(false, true);
assertEquals("\n\n1\n\n\n2\n", text);
// Both
text = extractor.getText(true, true, false);
String bothText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n\n\n1\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n\n\n2\n";
assertEquals(bothText, text);
// With Slides and Master Text
text = extractor.getText(true, false, true);
String smText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n";
assertEquals(smText, text);
// With Slides, Notes and Master Text
text = extractor.getText(true, true, true);
String snmText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n\n\n1\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n\n\n2\n";
assertEquals(snmText, text);
// Via set defaults
extractor.setSlidesByDefault(false);
extractor.setNotesByDefault(true);
text = extractor.getText();
assertEquals("\n\n1\n\n\n2\n", text);
extractor.close();
xmlA.close();
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class TestXSLFPowerPointExtractor method testDifferentSubformats.
/**
* Test that we can get the text from macro enabled,
* template, theme, slide enabled etc formats, as
* well as from the normal file
*/
@Test
public void testDifferentSubformats() throws Exception {
String[] extensions = new String[] { "pptx", "pptm", "ppsm", "ppsx", "thmx" };
for (String extension : extensions) {
String filename = "testPPT." + extension;
XMLSlideShow xml = openPPTX(filename);
XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
String text = extractor.getText();
if (extension.equals("thmx")) {
// Theme file doesn't have any textual content
assertEquals(filename, 0, text.length());
continue;
}
assertTrue(filename, text.length() > 0);
assertContains(filename, text, "Attachment Test");
assertContains(filename, text, "This is a test file data with the same content");
assertContains(filename, text, "content parsing");
assertContains(filename, text, "Different words to test against");
assertContains(filename, text, "Mystery");
extractor.close();
xml.close();
}
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class TestXSLFPowerPointExtractor method testGetComments.
public void testGetComments() throws IOException {
XMLSlideShow xml = openPPTX("45545_Comment.pptx");
XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
String text = extractor.getText();
assertTrue(text.length() > 0);
// Check comments are there
assertContains(text, "testdoc");
assertContains(text, "test phrase");
// Check the authors came through too
assertContains(text, "XPVMWARE01");
extractor.close();
xml.close();
}
Aggregations