Example usage for org.apache.poi.xslf.usermodel XMLSlideShow XMLSlideShow

List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow XMLSlideShow

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XMLSlideShow XMLSlideShow.

Prototype

public XMLSlideShow() 

Source Link

Usage

From source file:info.informationsea.venn.VennExporter.java

License:Open Source License

public static <T, U> void exportAsPowerPoint(VennFigureParameters<T> parameters, File file) throws IOException {
    XMLSlideShow slideShow = new XMLSlideShow();
    XSLFSlide slide = slideShow.createSlide();
    VennDrawSlides<T> vennDrawSlides = new VennDrawSlides<>(VennFigureCreator.createVennFigure(parameters),
            slide);/*w w w .  java  2 s . c  o  m*/
    vennDrawSlides.draw();
    try (OutputStream os = new FileOutputStream(file)) {
        slideShow.write(os);
    }
}

From source file:info.opencards.util.playground.SlidesAndShapes.java

License:Apache License

public static void main(String[] args) throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    ppt.setPageSize(new Dimension(792, 612));

    XSLFSlide slide1 = ppt.createSlide();
    XSLFTextBox textBox = slide1.createTextBox();
    XSLFTextRun r1 = textBox.addNewTextParagraph().addNewTextRun();
    r1.setBold(true);//from www  .  ja va2  s  . c  o  m
    r1.setItalic(true);
    r1.setFontColor(Color.yellow);
    r1.setFontFamily("Arial");
    r1.setFontSize(24);
    r1.setText("Apache");
    XSLFTextRun r2 = textBox.addNewTextParagraph().addNewTextRun();
    r2.setStrikethrough(true);
    r2.setUnderline(true);
    r2.setText("POI\u2122");
    XSLFTextRun r3 = textBox.addNewTextParagraph().addNewTextRun();
    r3.setFontFamily("Wingdings");
    r3.setText(" Version 3.8");

    textBox.setAnchor(new Rectangle(50, 50, 200, 100));
    textBox.setLineColor(Color.black);
    textBox.setFillColor(Color.orange);

    XSLFAutoShape shape2 = slide1.createAutoShape();

    shape2.setAnchor(new Rectangle(100, 100, 200, 200));

    XSLFFreeformShape shape3 = slide1.createFreeform();
    Rectangle rect = new Rectangle(150, 150, 300, 300);
    GeneralPath path = new GeneralPath(rect);
    path.append(new Ellipse2D.Double(200, 200, 100, 50), false);
    shape3.setPath(path);
    shape3.setAnchor(path.getBounds2D());
    shape3.setLineColor(Color.black);
    shape3.setFillColor(Color.lightGray);

    XSLFSlide slide2 = ppt.createSlide();
    XSLFGroupShape group = slide2.createGroup();

    group.setAnchor(new Rectangle(0, 0, 792, 612));
    group.setInteriorAnchor(new Rectangle(-10, -10, 20, 20));

    XSLFAutoShape shape4 = group.createAutoShape();
    shape4.setAnchor(new Rectangle(0, 0, 5, 5));
    shape4.setLineWidth(5);
    shape4.setLineColor(Color.black);

    FileOutputStream out = new FileOutputStream("xslf-demo.pptx");
    ppt.write(out);
    out.close();
}

From source file:org.maptalks.poi.animation.TestXSLFAnimationGroup.java

License:Apache License

@Test
public void testAnimationGroup() throws Exception {
    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    Dimension pageSize = pptx.getPageSize();
    //        Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight());
    Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight());
    List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>();
    XSLFAnimation animation = new XSLFAnimation();
    String[] directions = new String[5];
    directions[0] = MoveDirection.BOTTOM;
    directions[1] = MoveDirection.LEFT;/*from  ww  w . j av  a  2s .co m*/
    directions[2] = MoveDirection.TOP;
    directions[3] = MoveDirection.RIGHT;
    directions[4] = MoveDirection.BOTTOM;
    String pathStr = this.getClass().getResource("/images").getPath();
    String nodeType = "clickEffect";
    for (int i = 0; i < 3; i++) {
        String fileName = pathStr + "/" + (i + 1) + ".png";
        File downloadeFile = new File(fileName);
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        int size = 0;
        byte[] temp = new byte[1024];
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
        XSLFPictureData pictureData = pptx.addPicture(content,
                org.apache.poi.sl.usermodel.PictureData.PictureType.PNG);
        XSLFPictureShape picShape = slide.createPicture(pictureData);
        picShape.setAnchor(rectangle);
        picShape.setLineWidth(0);

        if (i > 1) {
            nodeType = "afterEffect";
            XSLFAnimationType animationType = new FlyIn(picShape, directions[i], nodeType);
            animationTypes.get(1).addChild(animationType);
        } else {
            XSLFAnimationType animationType = new FlyIn(picShape, directions[i], nodeType);
            animationTypes.add(animationType);
        }
    }
    animation.addAnimationToSlide(slide, animationTypes);
    FileOutputStream out = new FileOutputStream("d:\\group.pptx");
    //        FileOutputStream out = new FileOutputStream(pathStr+"/group.pptx");
    pptx.write(out);
    out.close();
}

From source file:org.maptalks.poi.animation.TestXSLFAnimationShape.java

License:Apache License

@Test
public void testAnimationSlide() throws Exception {
    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    Dimension pageSize = pptx.getPageSize();
    //        Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight());
    Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight());
    List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>();
    XSLFAnimation animation = new XSLFAnimation();
    String[] directions = new String[5];
    directions[0] = MoveDirection.BOTTOM;
    directions[1] = MoveDirection.LEFT;//  w w  w  . j av a  2s  .c  o m
    directions[2] = MoveDirection.TOP;
    directions[3] = MoveDirection.RIGHT;
    directions[4] = MoveDirection.BOTTOM;
    String pathStr = this.getClass().getResource("/images").getPath();
    for (int i = 0; i < 3; i++) {
        String fileName = pathStr + "/" + (i + 1) + ".png";
        File downloadeFile = new File(fileName);
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        int size = 0;
        byte[] temp = new byte[1024];
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
        XSLFPictureData pictureData = pptx.addPicture(content,
                org.apache.poi.sl.usermodel.PictureData.PictureType.PNG);
        XSLFPictureShape picShape = slide.createPicture(pictureData);
        picShape.setAnchor(rectangle);
        picShape.setLineWidth(0);
        XSLFAnimationType animationType = new FlyIn(picShape, directions[i]);
        animationTypes.add(animationType);

        XSLFAnimationType animationOutType = new FlyOut(picShape, directions[i]);
        animationTypes.add(animationOutType);
    }
    slide = animation.addAnimationToSlide(slide, animationTypes);
    FileOutputStream out = new FileOutputStream("d:\\temp.pptx");
    //        FileOutputStream out = new FileOutputStream(pathStr+"/temp.pptx");
    pptx.write(out);
    out.close();
}

From source file:org.maptalks.poi.animation.TestZoomIn.java

License:Apache License

@Test
public void testAnimationSlide() throws Exception {
    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    Dimension pageSize = pptx.getPageSize();
    Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight());
    //        Rectangle2D rectangle = new Rectangle2D.Double();
    List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>();
    XSLFAnimation animation = new XSLFAnimation();
    String[] directions = new String[5];
    directions[0] = MoveDirection.BOTTOM;
    directions[1] = MoveDirection.LEFT;//w w  w.j  a v  a  2 s  .co m
    directions[2] = MoveDirection.TOP;
    directions[3] = MoveDirection.RIGHT;
    directions[4] = MoveDirection.BOTTOM;
    String pathStr = this.getClass().getResource("/images").getPath();
    for (int i = 0; i < 3; i++) {
        String fileName = pathStr + "/" + (i + 1) + ".png";
        File downloadeFile = new File(fileName);
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        int size = 0;
        byte[] temp = new byte[1024];
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
        XSLFPictureData pictureData = pptx.addPicture(content,
                org.apache.poi.sl.usermodel.PictureData.PictureType.PNG);
        XSLFPictureShape picShape = slide.createPicture(pictureData);
        picShape.setAnchor(rectangle);
        picShape.setLineWidth(0);
        XSLFAnimationType animationType = new ZoomIn(picShape, directions[i]);
        animationTypes.add(animationType);

        XSLFAnimationType animationOutType = new FlyOut(picShape, directions[i]);
        animationTypes.add(animationOutType);
    }
    slide = animation.addAnimationToSlide(slide, animationTypes);
    FileOutputStream out = new FileOutputStream("d:\\zoomin.pptx");
    //        FileOutputStream out = new FileOutputStream(pathStr+"/zoomin.pptx");
    pptx.write(out);
    out.close();
}

From source file:org.maptalks.poi.animation.TestZoomOut.java

License:Apache License

@Test
public void testAnimationSlide() throws Exception {
    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    Dimension pageSize = pptx.getPageSize();
    //        Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight());
    Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight());
    List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>();
    XSLFAnimation animation = new XSLFAnimation();
    String[] directions = new String[5];
    directions[0] = MoveDirection.BOTTOM;
    directions[1] = MoveDirection.LEFT;/*from   w  w w.  j  a  v a2s .  c  o  m*/
    directions[2] = MoveDirection.TOP;
    directions[3] = MoveDirection.RIGHT;
    directions[4] = MoveDirection.BOTTOM;
    String pathStr = this.getClass().getResource("/images").getPath();
    for (int i = 0; i < 3; i++) {
        String fileName = pathStr + "/" + (i + 1) + ".png";
        File downloadeFile = new File(fileName);
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        int size = 0;
        byte[] temp = new byte[1024];
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
        XSLFPictureData pictureData = pptx.addPicture(content,
                org.apache.poi.sl.usermodel.PictureData.PictureType.PNG);
        XSLFPictureShape picShape = slide.createPicture(pictureData);
        picShape.setAnchor(rectangle);
        picShape.setLineWidth(0);
        XSLFAnimationType animationType = new ZoomIn(picShape, directions[i]);
        animationTypes.add(animationType);

        XSLFAnimationType animationOutType = new ZoomOut(picShape, directions[i]);
        animationTypes.add(animationOutType);
    }
    slide = animation.addAnimationToSlide(slide, animationTypes);
    FileOutputStream out = new FileOutputStream("d:\\zoomout.pptx");
    //        FileOutputStream out = new FileOutputStream(pathStr+"/zoomout.pptx");
    pptx.write(out);
    out.close();
}

From source file:poi.xslf.usermodel.MergePresentations.java

License:Apache License

public static void main(String args[]) throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();

    for (String arg : args) {
        FileInputStream is = new FileInputStream(arg);
        XMLSlideShow src = new XMLSlideShow(is);
        is.close();/*  w w w  .  j a va 2  s.  c  o  m*/

        for (XSLFSlide srcSlide : src.getSlides()) {
            ppt.createSlide().importContent(srcSlide);
        }
    }

    FileOutputStream out = new FileOutputStream("merged.pptx");
    ppt.write(out);
    out.close();
}

From source file:poi.xslf.usermodel.tutorial.Step2.java

License:Apache License

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());
        }//from w w  w. j  a va  2 s  .  c  om
    }

    // blank slide
    XSLFSlide blankSlide = ppt.createSlide();

    XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[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);
    body2.clearText(); // unset any existing text
    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();

}

From source file:poi.xslf.usermodel.Tutorial2.java

License:Apache License

public static void main(String[] args) throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();

    XSLFSlide slide1 = ppt.createSlide();
    XSLFTextBox shape1 = slide1.createTextBox();
    // initial height of the text box is 100 pt but
    Rectangle anchor = new Rectangle(10, 100, 300, 100);
    shape1.setAnchor(anchor);//from   w  w w.ja v a 2  s  . c o  m

    XSLFTextParagraph p1 = shape1.addNewTextParagraph();
    XSLFTextRun r1 = p1.addNewTextRun();
    r1.setText("Paragraph Formatting");
    r1.setFontSize(24);
    r1.setFontColor(new Color(85, 142, 213));

    XSLFTextParagraph p2 = shape1.addNewTextParagraph();
    // If spaceBefore >= 0, then space is a percentage of normal line height.
    // If spaceBefore < 0, the absolute value of linespacing is the spacing in points
    p2.setSpaceBefore(-20); // 20 pt from the previous paragraph
    p2.setSpaceAfter(300); // 3 lines after the paragraph
    XSLFTextRun r2 = p2.addNewTextRun();
    r2.setText("Paragraph  properties apply to all text residing within the corresponding paragraph.");
    r2.setFontSize(16);

    XSLFTextParagraph p3 = shape1.addNewTextParagraph();

    XSLFTextRun r3 = p3.addNewTextRun();
    r3.setText("Run Formatting");
    r3.setFontSize(24);
    r3.setFontColor(new Color(85, 142, 213));

    XSLFTextParagraph p4 = shape1.addNewTextParagraph();
    p4.setSpaceBefore(-20); // 20 pt from the previous paragraph
    p4.setSpaceAfter(300); // 3 lines after the paragraph
    XSLFTextRun r4 = p4.addNewTextRun();
    r4.setFontSize(16);
    r4.setText("Run level formatting is the most granular property level and allows "
            + "for the specifying of all low level text properties. The text run is "
            + "what all paragraphs are derived from and thus specifying various "
            + "properties per run will allow for a diversely formatted text paragraph.");

    // resize the shape to fit text
    shape1.resizeToFitText();

    FileOutputStream out = new FileOutputStream("text.pptx");
    ppt.write(out);
    out.close();
}

From source file:poi.xslf.usermodel.Tutorial3.java

License:Apache License

public static void main(String[] args) throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();

    XSLFSlide slide = ppt.createSlide();

    XSLFTextShape titleShape = slide.createTextBox();
    titleShape.setPlaceholder(Placeholder.TITLE);
    titleShape.setText("This is a slide title");
    titleShape.setAnchor(new Rectangle(50, 50, 400, 100));

    FileOutputStream out = new FileOutputStream("title.pptx");
    ppt.write(out);//from ww  w  .  ja va 2  s  .co  m
    out.close();
}