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

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

Introduction

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

Prototype

@SuppressWarnings("resource")
public final void write(OutputStream stream) throws IOException 

Source Link

Document

Write out this document to an Outputstream.

Usage

From source file:Tutorial1.java

License:Apache License

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

    // XSLFSlide#createSlide() with no arguments creates a blank slide
    XSLFSlide blankSlide = ppt.createSlide();

    XSLFSlideMaster master = ppt.getSlideMasters()[0];

    XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);
    XSLFSlide slide1 = ppt.createSlide(layout1);
    XSLFTextShape[] ph1 = slide1.getPlaceholders();
    XSLFTextShape titlePlaceholder1 = ph1[0];
    titlePlaceholder1.setText("This is a title");
    XSLFTextShape subtitlePlaceholder1 = ph1[1];
    subtitlePlaceholder1.setText("this is a subtitle");

    XSLFSlideLayout layout2 = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide2 = ppt.createSlide(layout2);
    XSLFTextShape[] ph2 = slide2.getPlaceholders();
    XSLFTextShape titlePlaceholder2 = ph2[0];
    titlePlaceholder2.setText("This is a title");
    XSLFTextShape bodyPlaceholder = ph2[1];
    // we are going to add text by paragraphs. Clear the default placehoder text before that
    bodyPlaceholder.clearText();/*  ww  w .  java 2 s.c  o  m*/
    XSLFTextParagraph p1 = bodyPlaceholder.addNewTextParagraph();
    p1.setLevel(0);
    p1.addNewTextRun().setText("Level1 text");
    XSLFTextParagraph p2 = bodyPlaceholder.addNewTextParagraph();
    p2.setLevel(1);
    p2.addNewTextRun().setText("Level2 text");
    XSLFTextParagraph p3 = bodyPlaceholder.addNewTextParagraph();
    p3.setLevel(3);
    p3.addNewTextRun().setText("Level3 text");

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

From source file:AddAudioToPptx.java

License:Apache License

public static void main(String[] args) throws Exception {
    URL video = new URL("http://archive.org/download/test-mpeg/test-mpeg.mpg");
    // URL video = new URL("file:test-mpeg.mpg");

    XMLSlideShow pptx = new XMLSlideShow();

    // add video file
    String videoFileName = "lego_edsheeran.mp3";
    PackagePartName partName = PackagingURIHelper.createPartName("/ppt/media/" + videoFileName);
    PackagePart part = pptx.getPackage().createPart(partName, "audio/mpeg");
    OutputStream partOs = part.getOutputStream();
    //InputStream fis = video.openStream();
    FileInputStream fis = new FileInputStream(videoFileName);
    byte buf[] = new byte[1024];
    for (int readBytes; (readBytes = fis.read(buf)) != -1; partOs.write(buf, 0, readBytes))
        ;//from  w w w.j  av  a 2  s.  com
    fis.close();
    partOs.close();

    XSLFSlide slide1 = pptx.createSlide();

    byte[] picture = IOUtils.toByteArray(new FileInputStream("audio.png"));

    //adding the image to the presentation
    XSLFPictureData idx = pptx.addPicture(picture, XSLFPictureData.PictureType.PNG);

    //creating a slide with given picture on it
    XSLFPictureShape pv1 = slide1.createPicture(idx);

    //XSLFPictureShape pv1 = // addPreview(pptx, slide1, part, 5, 50, 80);
    addAudio(pptx, slide1, part, pv1, 5);
    addTimingInfo(slide1, pv1);
    //XSLFPictureShape pv2 = addPreview(pptx, slide1, part, 9, 50, 250);
    //addVideo(pptx, slide1, part, pv2, 9);
    //addTimingInfo(slide1, pv2);

    FileOutputStream fos = new FileOutputStream("pptx-with-audio.pptx");
    pptx.write(fos);
    fos.close();

    pptx.close();
}

From source file:AddVideoToPptx.java

License:Apache License

public static void main(String[] args) throws Exception {
    URL video = new URL("http://archive.org/download/test-mpeg/test-mpeg.mpg");
    // URL video = new URL("file:test-mpeg.mpg");

    XMLSlideShow pptx = new XMLSlideShow();

    // add video file
    String videoFileName = video.getPath().substring(video.getPath().lastIndexOf('/') + 1);
    PackagePartName partName = PackagingURIHelper.createPartName("/ppt/media/" + videoFileName);
    PackagePart part = pptx.getPackage().createPart(partName, "video/mpeg");
    OutputStream partOs = part.getOutputStream();
    //InputStream fis = video.openStream();
    FileInputStream fis = new FileInputStream("Lea Michele - Cannonball.mp4");
    byte buf[] = new byte[1024];
    for (int readBytes; (readBytes = fis.read(buf)) != -1; partOs.write(buf, 0, readBytes))
        ;/*from w ww . j a va  2  s .c o m*/
    fis.close();
    partOs.close();

    XSLFSlide slide1 = pptx.createSlide();
    XSLFPictureShape pv1 = addPreview(pptx, slide1, part, 5, 50, 80);
    addVideo(pptx, slide1, part, pv1, 5);
    addTimingInfo(slide1, pv1);
    //XSLFPictureShape pv2 = addPreview(pptx, slide1, part, 9, 50, 250);
    //addVideo(pptx, slide1, part, pv2, 9);
    //addTimingInfo(slide1, pv2);

    FileOutputStream fos = new FileOutputStream("pptx-with-video.pptx");
    pptx.write(fos);
    fos.close();

    pptx.close();
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

private void testWrite(final XMLSlideShow pptx) throws IOException {
    final File temp = createTempFile("temp", ".pptx");

    if (!Boolean.valueOf(System.getProperty("keep.powerpoint.output", "false"))) {
        temp.deleteOnExit();//ww w  .jav a2 s  .  c o m
    }

    pptx.write(new FileOutputStream(temp));
}

From source file:easyoffice.powerpoint.PPTMaker.java

private static boolean savePpt(XMLSlideShow ppt) {

    /*/*from www .j  a v  a  2s.  c o m*/
    * Save PPT instance on disk and add pptx extension
    * if not included in filename
     */
    if (!OUTPUT_PPT_NAME.endsWith(".pptx")) {
        OUTPUT_PPT_NAME += ".pptx";
    }

    try {
        File file = new File(OUTPUT_PPT_NAME);
        FileOutputStream out = new FileOutputStream(file);
        ppt.write(out);
        out.close();

        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:info.informationsea.venn.graphics.VennDrawSlidesTest.java

License:Open Source License

@Test
public void testDraw() throws Exception {
    VennFigure<String> vennFigure = new VennFigure<>();
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(0, 0), 0, 100, 100));
    vennFigure.addShape(new VennFigure.Text<>(new VennFigure.Point(0, 0), "Normal"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(50, 50), 0, 50, 100));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(200, 200), Math.PI / 4, 50, 100));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 0), 0, 50, 20, "#00ff00ff"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 20), 0, 50, 20, "#ff0000ff"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 40), 0, 50, 20, "#0000ffff"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 60), 0, 50, 20, "#00ff0050"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 80), 0, 50, 20, "#00ff0020"));
    vennFigure.addShape(new VennFigure.Oval<>(new VennFigure.Point(150, 100), 0, 50, 20, "#00ff00"));
    vennFigure.addShape(new VennFigure.Text<>(new VennFigure.Point(200, 200), "Rotated"));
    vennFigure.addShape(new VennFigure.Text<>(new VennFigure.Point(100, 100), "Center"));
    vennFigure//from  w  w w  .  ja  va 2 s.  co m
            .addShape(new VennFigure.Text<>(new VennFigure.Point(100, 120), "Left", VennFigure.TextJust.LEFT));
    vennFigure.addShape(
            new VennFigure.Text<>(new VennFigure.Point(100, 140), "Right", VennFigure.TextJust.RIGHT));

    XMLSlideShow slideShow = new XMLSlideShow();
    XSLFSlideMaster slideMaster = slideShow.getSlideMasters()[0];
    VennDrawSlides<String> drawSlides = new VennDrawSlides<>(vennFigure,
            slideShow.createSlide(slideMaster.getLayout(SlideLayout.TITLE_ONLY)));
    drawSlides.draw();

    try (FileOutputStream fos = new FileOutputStream(new File(DIST_DIR, "test.pptx"))) {
        slideShow.write(fos);
    }
}

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);/*from  ww w.  j  av  a 2s .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 ww  w.jav a  2s  . com*/
    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.joeffice.presentation.PptxDataObject.java

License:Apache License

@Override
public void save(File file) throws IOException {
    XMLSlideShow presentation = (XMLSlideShow) getDocument();
    try (FileOutputStream pptxOutputStream = new FileOutputStream(file)) {
        presentation.write(pptxOutputStream);
    }//w w w  .  j a  v  a  2s . c  o m
}

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