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();
}
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();
}
Aggregations