Search in sources :

Example 16 with HSLFSlideShowImpl

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;
}
Also used : DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 17 with HSLFSlideShowImpl

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();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) File(java.io.File) FileInputStream(java.io.FileInputStream) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 18 with HSLFSlideShowImpl

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFSlideMaster(org.apache.poi.hslf.usermodel.HSLFSlideMaster) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 19 with HSLFSlideShowImpl

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 20 with HSLFSlideShowImpl

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();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Aggregations

HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)27 Test (org.junit.Test)11 Record (org.apache.poi.hslf.record.Record)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)5 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)5 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)4 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 POIDataSamples (org.apache.poi.POIDataSamples)3 Document (org.apache.poi.hslf.record.Document)3 PersistPtrHolder (org.apache.poi.hslf.record.PersistPtrHolder)3 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)3 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)3 File (java.io.File)2 CurrentUserAtom (org.apache.poi.hslf.record.CurrentUserAtom)2 Notes (org.apache.poi.hslf.record.Notes)2