Search in sources :

Example 6 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape 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 7 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project poi by apache.

the class HeadersFooters method isVisible.

private boolean isVisible(int flag, Placeholder placeholderId) {
    boolean visible;
    if (_ppt2007) {
        HSLFSimpleShape ss = _sheet.getPlaceholder(placeholderId);
        visible = ss instanceof HSLFTextShape && ((HSLFTextShape) ss).getText() != null;
    } else {
        visible = _container.getHeadersFootersAtom().getFlag(flag);
    }
    return visible;
}
Also used : HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSimpleShape(org.apache.poi.hslf.usermodel.HSLFSimpleShape)

Aggregations

HSLFTextShape (org.apache.poi.hslf.usermodel.HSLFTextShape)7 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)4 HSLFSimpleShape (org.apache.poi.hslf.usermodel.HSLFSimpleShape)2 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Comment (org.apache.poi.hslf.model.Comment)1 HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)1 CString (org.apache.poi.hslf.record.CString)1 HSLFNotes (org.apache.poi.hslf.usermodel.HSLFNotes)1 HSLFSlideMaster (org.apache.poi.hslf.usermodel.HSLFSlideMaster)1 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)1 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)1 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)1