Search in sources :

Example 1 with XSLFSlideMaster

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

the class Step2 method main.

public static void main(String[] args) throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    // first see what slide layouts are available by default
    System.out.println("Available slide layouts:");
    for (XSLFSlideMaster master : ppt.getSlideMasters()) {
        for (XSLFSlideLayout layout : master.getSlideLayouts()) {
            System.out.println(layout.getType());
        }
    }
    // blank slide
    /*XSLFSlide blankSlide =*/
    ppt.createSlide();
    XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
    // title slide
    XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
    XSLFSlide slide1 = ppt.createSlide(titleLayout);
    XSLFTextShape title1 = slide1.getPlaceholder(0);
    title1.setText("First Title");
    // title and content
    XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);
    XSLFTextShape title2 = slide2.getPlaceholder(0);
    title2.setText("Second Title");
    XSLFTextShape body2 = slide2.getPlaceholder(1);
    // unset any existing text
    body2.clearText();
    body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
    FileOutputStream out = new FileOutputStream("step2.pptx");
    ppt.write(out);
    out.close();
    ppt.close();
}
Also used : XSLFSlideMaster(org.apache.poi.xslf.usermodel.XSLFSlideMaster) XSLFSlide(org.apache.poi.xslf.usermodel.XSLFSlide) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFTextShape(org.apache.poi.xslf.usermodel.XSLFTextShape) FileOutputStream(java.io.FileOutputStream) XSLFSlideLayout(org.apache.poi.xslf.usermodel.XSLFSlideLayout)

Example 2 with XSLFSlideMaster

use of org.apache.poi.xslf.usermodel.XSLFSlideMaster 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

XSLFSlideLayout (org.apache.poi.xslf.usermodel.XSLFSlideLayout)2 XSLFSlideMaster (org.apache.poi.xslf.usermodel.XSLFSlideMaster)2 FileOutputStream (java.io.FileOutputStream)1 XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)1 XSLFCommentAuthors (org.apache.poi.xslf.usermodel.XSLFCommentAuthors)1 XSLFComments (org.apache.poi.xslf.usermodel.XSLFComments)1 XSLFNotes (org.apache.poi.xslf.usermodel.XSLFNotes)1 XSLFSlide (org.apache.poi.xslf.usermodel.XSLFSlide)1 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)1 CTComment (org.openxmlformats.schemas.presentationml.x2006.main.CTComment)1 CTCommentAuthor (org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor)1