Search in sources :

Example 1 with XSLFComments

use of org.apache.poi.xslf.usermodel.XSLFComments in project poi by apache.

the class XSLFPowerPointExtractor method getText.

/**
    * Gets the requested text from the slide
    * 
    * @param slide the slide to retrieve the text from
    * @param slideText Should we retrieve text from slides?
    * @param notesText Should we retrieve text from notes?
    * @param masterText Should we retrieve text from master slides?
    * 
    * @return the extracted text
    */
public static String getText(XSLFSlide slide, boolean slideText, boolean notesText, boolean masterText) {
    StringBuilder text = new StringBuilder();
    XSLFCommentAuthors commentAuthors = slide.getSlideShow().getCommentAuthors();
    XSLFNotes notes = slide.getNotes();
    XSLFComments comments = slide.getComments();
    XSLFSlideLayout layout = slide.getSlideLayout();
    XSLFSlideMaster master = layout.getSlideMaster();
    // Do the slide's text if requested
    if (slideText) {
        extractText(slide, false, text);
        // If requested, get text from the master and it's layout 
        if (masterText) {
            assert (layout != null);
            extractText(layout, true, text);
            assert (master != null);
            extractText(master, true, text);
        }
        // If the slide has comments, do those too
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmArray()) {
                // Do the author if we can
                if (commentAuthors != null) {
                    CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
                    if (author != null) {
                        text.append(author.getName() + ": ");
                    }
                }
                // Then the comment text, with a new line afterwards
                text.append(comment.getText());
                text.append("\n");
            }
        }
    }
    // Do the notes if requested
    if (notesText && notes != null) {
        extractText(notes, false, text);
    }
    return text.toString();
}
Also used : XSLFCommentAuthors(org.apache.poi.xslf.usermodel.XSLFCommentAuthors) XSLFSlideMaster(org.apache.poi.xslf.usermodel.XSLFSlideMaster) CTComment(org.openxmlformats.schemas.presentationml.x2006.main.CTComment) XSLFComments(org.apache.poi.xslf.usermodel.XSLFComments) CTCommentAuthor(org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor) XSLFSlideLayout(org.apache.poi.xslf.usermodel.XSLFSlideLayout) XSLFNotes(org.apache.poi.xslf.usermodel.XSLFNotes)

Aggregations

XSLFCommentAuthors (org.apache.poi.xslf.usermodel.XSLFCommentAuthors)1 XSLFComments (org.apache.poi.xslf.usermodel.XSLFComments)1 XSLFNotes (org.apache.poi.xslf.usermodel.XSLFNotes)1 XSLFSlideLayout (org.apache.poi.xslf.usermodel.XSLFSlideLayout)1 XSLFSlideMaster (org.apache.poi.xslf.usermodel.XSLFSlideMaster)1 CTComment (org.openxmlformats.schemas.presentationml.x2006.main.CTComment)1 CTCommentAuthor (org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor)1