Search in sources :

Example 6 with HeadersFooters

use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.

the class TestHeadersFooters method bug58144a.

@Test
public void bug58144a() throws IOException {
    assumeFalse(xslfOnly);
    SlideShow<?, ?> ppt = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
    HSLFSlide sl = (HSLFSlide) ppt.getSlides().get(0);
    HeadersFooters hfs = sl.getHeadersFooters();
    assertNull(hfs.getHeaderText());
    assertEquals("Confidential", hfs.getFooterText());
    List<List<HSLFTextParagraph>> llp = sl.getTextParagraphs();
    assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
    assertFalse(llp.get(0).get(0).isHeaderOrFooter());
    ppt.close();
}
Also used : HeadersFooters(org.apache.poi.hslf.model.HeadersFooters) List(java.util.List) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 7 with HeadersFooters

use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.

the class PowerPointExtractor method getText.

public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText, boolean getMasterText) {
    StringBuffer ret = new StringBuffer();
    if (getSlideText) {
        if (getMasterText) {
            for (HSLFSlideMaster master : _show.getSlideMasters()) {
                for (HSLFShape sh : master.getShapes()) {
                    if (sh instanceof HSLFTextShape) {
                        HSLFTextShape hsh = (HSLFTextShape) sh;
                        final String text = hsh.getText();
                        if (text == null || "".equals(text) || "*".equals(text)) {
                            continue;
                        }
                        if (HSLFMasterSheet.isPlaceholder(sh)) {
                            // check for metro shape of complex placeholder
                            boolean isMetro = new HSLFMetroShape<HSLFShape>(sh).hasMetroBlob();
                            if (!isMetro) {
                                // don't bother about boiler plate text on master sheets
                                LOG.log(POILogger.INFO, "Ignoring boiler plate (placeholder) text on slide master:", text);
                                continue;
                            }
                        }
                        ret.append(text);
                        if (!text.endsWith("\n")) {
                            ret.append("\n");
                        }
                    }
                }
            }
        }
        for (HSLFSlide slide : _slides) {
            String headerText = "";
            String footerText = "";
            HeadersFooters hf = slide.getHeadersFooters();
            if (hf != null) {
                if (hf.isHeaderVisible()) {
                    headerText = safeLine(hf.getHeaderText());
                }
                if (hf.isFooterVisible()) {
                    footerText = safeLine(hf.getFooterText());
                }
            }
            // Slide header, if set
            ret.append(headerText);
            // Slide text
            textRunsToText(ret, slide.getTextParagraphs());
            // Table text
            for (HSLFShape shape : slide.getShapes()) {
                if (shape instanceof HSLFTable) {
                    extractTableText(ret, (HSLFTable) shape);
                }
            }
            // Slide footer, if set
            ret.append(footerText);
            // Comments, if requested and present
            if (getCommentText) {
                for (Comment comment : slide.getComments()) {
                    ret.append(comment.getAuthor() + " - " + comment.getText() + "\n");
                }
            }
        }
        if (getNoteText) {
            ret.append('\n');
        }
    }
    if (getNoteText) {
        // Not currently using _notes, as that can have the notes of
        // master sheets in. Grab Slide list, then work from there,
        // but ensure no duplicates
        Set<Integer> seenNotes = new HashSet<Integer>();
        String headerText = "";
        String footerText = "";
        HeadersFooters hf = _show.getNotesHeadersFooters();
        if (hf != null) {
            if (hf.isHeaderVisible()) {
                headerText = safeLine(hf.getHeaderText());
            }
            if (hf.isFooterVisible()) {
                footerText = safeLine(hf.getFooterText());
            }
        }
        for (HSLFSlide slide : _slides) {
            HSLFNotes notes = slide.getNotes();
            if (notes == null) {
                continue;
            }
            Integer id = Integer.valueOf(notes._getSheetNumber());
            if (seenNotes.contains(id)) {
                continue;
            }
            seenNotes.add(id);
            // Repeat the Notes header, if set
            ret.append(headerText);
            // Notes text
            textRunsToText(ret, notes.getTextParagraphs());
            // Repeat the notes footer, if set
            ret.append(footerText);
        }
    }
    return ret.toString();
}
Also used : Comment(org.apache.poi.hslf.model.Comment) HSLFSlideMaster(org.apache.poi.hslf.usermodel.HSLFSlideMaster) HeadersFooters(org.apache.poi.hslf.model.HeadersFooters) HSLFNotes(org.apache.poi.hslf.usermodel.HSLFNotes) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTable(org.apache.poi.hslf.usermodel.HSLFTable) HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HashSet(java.util.HashSet)

Example 8 with HeadersFooters

use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.

the class TestBugs method bug55732.

@Test
public void bug55732() throws IOException {
    HSLFSlideShow ppt = open("bug55732.ppt");
    List<HSLFSlide> _slides = ppt.getSlides();
    /* Iterate over slides and extract text */
    for (HSLFSlide slide : _slides) {
        HeadersFooters hf = slide.getHeadersFooters();
        /*boolean visible =*/
        // exception happens here
        hf.isHeaderVisible();
    }
    ppt.close();
}
Also used : HeadersFooters(org.apache.poi.hslf.model.HeadersFooters) Test(org.junit.Test)

Aggregations

HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)8 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)2 Comment (org.apache.poi.hslf.model.Comment)2 HSLFNotes (org.apache.poi.hslf.usermodel.HSLFNotes)2 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)2 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1 SlideLayoutType (org.apache.poi.hslf.record.SlideAtomLayout.SlideLayoutType)1 HSLFSlideMaster (org.apache.poi.hslf.usermodel.HSLFSlideMaster)1 HSLFTextShape (org.apache.poi.hslf.usermodel.HSLFTextShape)1 Placeholder (org.apache.poi.sl.usermodel.Placeholder)1