use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestExtractor method assertExtractFromEmbedded.
private PowerPointExtractor assertExtractFromEmbedded(DirectoryNode root, String entryName, String expected) throws IOException {
DirectoryNode dir = (DirectoryNode) root.getEntry(entryName);
assertTrue(dir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT));
// Check the first file
HSLFSlideShowImpl ppt = new HSLFSlideShowImpl(dir);
PowerPointExtractor ppe = new PowerPointExtractor(ppt);
assertEquals(expected, ppe.getText(true, false));
return ppe;
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestExtractor method testDifferentPOIFS.
/**
* Tests that we can work with both {@link POIFSFileSystem}
* and {@link NPOIFSFileSystem}
*/
@SuppressWarnings("resource")
@Test
public void testDifferentPOIFS() throws IOException {
// Open the two filesystems
File pptFile = slTests.getFile("basic_test_ppt_file.ppt");
InputStream is1 = new FileInputStream(pptFile);
OPOIFSFileSystem opoifs = new OPOIFSFileSystem(is1);
is1.close();
NPOIFSFileSystem npoifs = new NPOIFSFileSystem(pptFile);
DirectoryNode[] files = { opoifs.getRoot(), npoifs.getRoot() };
// Open directly
for (DirectoryNode dir : files) {
PowerPointExtractor extractor = new PowerPointExtractor(dir);
assertEquals(expectText, extractor.getText());
}
// Open via a HSLFSlideShow
for (DirectoryNode dir : files) {
HSLFSlideShowImpl slideshow = new HSLFSlideShowImpl(dir);
PowerPointExtractor extractor = new PowerPointExtractor(slideshow);
assertEquals(expectText, extractor.getText());
extractor.close();
slideshow.close();
}
npoifs.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestSlideMaster method testChangeSlideMaster.
/**
* Check we can dynamically assign a slide master to a slide.
*/
@Test
public void testChangeSlideMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFSlideMaster> master = ppt.getSlideMasters();
List<HSLFSlide> slide = ppt.getSlides();
int sheetNo;
//each slide uses its own master
assertEquals(slide.get(0).getMasterSheet()._getSheetNumber(), master.get(0)._getSheetNumber());
assertEquals(slide.get(1).getMasterSheet()._getSheetNumber(), master.get(1)._getSheetNumber());
//all slides use the first master slide
sheetNo = master.get(0)._getSheetNumber();
for (HSLFSlide s : slide) {
s.setMasterSheet(master.get(0));
}
ByteArrayOutputStream out;
out = new ByteArrayOutputStream();
ppt.write(out);
out.close();
ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
master = ppt.getSlideMasters();
slide = ppt.getSlides();
for (HSLFSlide s : slide) {
assertEquals(sheetNo, s.getMasterSheet()._getSheetNumber());
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class HSLFTestDataSamples method writeOutAndReadBack.
/**
* Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back
* from a <tt>ByteArrayInputStream</tt>.<p/>
* Useful for verifying that the serialisation round trip
*/
public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return new HSLFSlideShowImpl(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TextStyleListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
if (records[i].getRecordType() == 1000l) {
Record docRecord = records[i];
Record[] docChildren = docRecord.getChildRecords();
for (int j = 0; j < docChildren.length; j++) {
if (docChildren[j] instanceof SlideListWithText) {
Record[] slwtChildren = docChildren[j].getChildRecords();
int lastTextLen = -1;
for (int k = 0; k < slwtChildren.length; k++) {
if (slwtChildren[k] instanceof TextCharsAtom) {
lastTextLen = ((TextCharsAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof TextBytesAtom) {
lastTextLen = ((TextBytesAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof StyleTextPropAtom) {
StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChildren[k];
stpa.setParentTextSize(lastTextLen);
showStyleTextPropAtom(stpa);
}
}
}
}
}
}
ss.close();
}
Aggregations