PowerPoint is used to create slide presentations
that can be displayed on projectors or big-screen TVs, and it is usually used
for marketing, training, education and other purposes. In order to improve the production
quality of PowerPoint, it is very important to master methods of slide
operation. In this article, I’ll show you how to add, hide, delete and reorder
presentation slides by using Free Spire.Presentation for Java.
Before getting started, please download the latest
version of Free Spire.Presentation for Java, unzip the package, and you’ll find
the Spire.Xls.jar file in the lib folder. Then import the jar file in your Java
IED. The following screenshot is what it finally looks like.
Example 1 Add slides
import com.spire.presentation.*;
public class AddSlide {
public static void main(String[] args) throws Exception {
public class AddSlide {
public static void main(String[] args) throws Exception {
//Create a PPT document and load file
Presentation presentation = new Presentation();
presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");
//add new slide at the end of the document
presentation.getSlides().append();
//insert a blank slide before the second slide
presentation.getSlides().insert(1);
//Save the document
presentation.saveToFile("output/AddSlide.pptx", FileFormat.PPTX_2010);
}
}
Presentation presentation = new Presentation();
presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");
//add new slide at the end of the document
presentation.getSlides().append();
//insert a blank slide before the second slide
presentation.getSlides().insert(1);
//Save the document
presentation.saveToFile("output/AddSlide.pptx", FileFormat.PPTX_2010);
}
}
Output
Example 2 Hide slides
import com.spire.presentation.*; public class HideSlide { public static void main(String[] args) throws Exception { //Create a PPT document and load file
Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //Hide the second slide presentation.getSlides().get(1).setHidden(true); //Save the document presentation.saveToFile("output/HideSlide.pptx", FileFormat.PPTX_2010); } }
Output
Example 3 Delete slidesimport com.spire.presentation.*; public class RemoveSlide { public static void main(String[] args) throws Exception { //Create a PPT document and load filePresentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //Remove the third slide presentation.getSlides().removeAt(2); //Save the document presentation.saveToFile("output/Removeslide.pptx", FileFormat.PPTX_2010); } }OutputExample 4 Reorder slidesimport com.spire.presentation.*; public class ReorderSlide { public static void main(String[] args) throws Exception { //Create a PPT document and load file Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //Move the first slide to the second slide position ISlide slide = presentation.getSlides().get(0); slide.setSlideNumber(2); //Save the document presentation.saveToFile("output/Reorderslide.pptx", FileFormat.PPTX_2010); } }Output
No comments:
Post a Comment