General

Components

Community

Development

PPMC

ASF

Documents > Cookbook >Slide



Add Slide
If you want to add new slide to the presentation document, you can use the following codes:
Here the SlideLayout is the layout model of the added slide, the first parameter is the index of the added slide and the second parameter is the name of this slide.

                PresentationDocument document=PresentationDocument.newPresentationDocument();                     
document.newSlide(1, "new slide", SlideLayout.TITLE_ONLY);


Get Slide
You can get the slide through the index in the presentation document, like follows:

        Slide slide;
slide=document.getSlideByIndex(0);

Or you can get the slide through the name of it by using the following code:

        slide=document.getSlideByName("new slide");

To get all the slides in the document,you can do like this:

        Iterator<Slide> slideList=document.getSlides();

Also you can get the number of the slides in the document by the following code:

        int numSlide=document.getSlideCount();


Set/Get Slide Name/Index
If you want to set a new name for a slide, you can use the following two methods:

        slide.setSlideName("second slide"); 
document.getSlideByIndex(2).setSlideName("third slide");

If you want to know the index and the name of one slide which is being operated, you can use the following codes:

        int slideIndex=slide.getSlideIndex();
String slideName=slide.getSlideName();


Copy Slide
You can copy a slide in the presentation document from one position to another by using the following codes:
Here the first parameter is the source position of the slide need to be copied, the second parameter is the destination position of the slide need to be copied, and the last parameter is the new name of the copied slide.

        document.copySlide(1, 2, "copied slide");

And also you can copy a slide from another document by using the following codes:
Here the first parameter of copyForeignSlide is the new position of the copied slide in the current document, the second parameter is the source document of the copied slide, and the last one is the slide index of the source document that need to be copied.

         PresentationDocument documentmodel;
documentmodel=(PresentationDocument)PresentationDocument.loadDocument("presentation.odp");
document.copyForeignSlide(1, documentmodel, 2);


Move/Delete Slide
To move one slide to another position of this presentation position, you can use the following codes:
Here the first parameter is the current index of the slide that need to be moved, and the second parameter is the index of the destination position before the move action.

        document.moveSlide(2, 1);       

You can delete the slide either by through the index or through the name of the specified slide, like follows:

        document.deleteSlideByIndex(1);
document.deleteSlideByName("third slide");


Add Text to Slide
You can set the text content of a slide with text box API since version 0.5. Below codes will get the title text box of a slide, set the text content, and then get the outline text box, set the list content.

        Textbox titleBox = slide.getTextboxByUsage(PresentationClass.TITLE).get(0);
titleBox.setTextContent("This is the title");
Textbox outline = slide.getTextboxByUsage(PresentationClass.OUTLINE).get(0);
List txtList = outline.addList();
txtList.addItem("List Item1");
txtList.addItem("List Item2");

To add some text, you can first get the notes of one slide and then add text to this corresponding notes. The following codes shows this process:

        Notes note=slide.getNotesPage();
note.addText("text notes");


Add Image to Slide
To add an image to slide, you can use below codes to simply add the image to the last slide of the presentation document.

        URI imageuri=new URI("namdaemun.jpg");
document.newImage(imageuri);

Or you can use following code to add an image to a specific position you want

        Slide slide1 = document.getSlideByIndex(1);
Image image = Image.newImage(slide1, new URI("http://www.xxx.com/a.jpg"));
FrameRectangle rect = image.getRectangle();
rect.setX(4);
rect.setY(5.7);
image.setRectangle(rect);



Powered by the Apache CMS.

Apache "ODF Toolkit" is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2011 The Apache Software Foundation Licensed under the Apache License, Version 2.0. Contact Us
Apache and the Apache feather logos are trademarks of The Apache Software Foundation.
Other names appearing on the site may be trademarks of their respective owners.