- Apache POI PPT - Discussion
- Apache POI PPT - Useful Resources
- Apache POI PPT - Quick Guide
- Apache POI PPT - PPT to Image
- Apache POI PPT - Merging
- Apache POI PPT - Formatting Text
- Apache POI PPT - Reading Shapes
- Apache POI PPT - Creating Hyperlinks
- Apache POI PPT - Images
- Apache POI PPT - Slide Management
- Apache POI PPT - Slide Layouts
- Apache POI PPT - Presentation
- Apache POI PPT - Classes & Methods
- Apache POI PPT - Installation
- Apache POI PPT - Java API Flavors
- Apache POI PPT - Overview
- Apache POI PPT - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache POI PPT - Spde Management
After completing this chapter, you will be able to delete, reorder, and perform read and write operations on a spde.
Changing a Spde
We can change the page size of a spde using the setPageSize() method of the XMLSpdeShow class.
Initially create a presentation as shown below −
File file = new File("C://POIPPT//Examples// TitleAndContentLayout.pptx"); //create presentation XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file));
Get the size of the current spde using the getPageSize() method of the XMLSpdeShow class.
java.awt.Dimension pgsize = ppt.getPageSize();
Set the size of the page using the setPageSize() method.
ppt.setPageSize(new java.awt.Dimension(1024, 768));
The complete program for changing the size of a spde is given below −
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xslf.usermodel.XMLSpdeShow; pubpc class ChangingSpde { pubpc static void main(String args[]) throws IOException { //create file object File file = new File("TitleAndContentLayout.pptx"); //create presentation XMLSpdeShow ppt = new XMLSpdeShow(); //getting the current page size java.awt.Dimension pgsize = ppt.getPageSize(); int pgw = pgsize.width; //spde width in points int pgh = pgsize.height; //spde height in points System.out.println("current page size of the PPT is:"); System.out.println("width :" + pgw); System.out.println("height :" + pgh); //set new page size ppt.setPageSize(new java.awt.Dimension(2048,1536)); //creating file object FileOutputStream out = new FileOutputStream(file); //saving the changes to a file ppt.write(out); System.out.println("spde size changed to given dimentions "); out.close(); } }
Save the above Java code as ChangingSpde.java, and then compile and execute it from the command prompt as follows −
$javac ChangingSpde.java $java ChangingSpde
It will compile and execute to generate the following output.
current page size of the presentation is : width :720 height :540 spde size changed to given dimensions
Given below is the snapshot of the presentation before changing the spde size −
The spde appears as follows after changing its size −
Reordering Spdes
You can set the spde order using the setSpdeOrder() method. Given below is the procedure to set the order of the spdes.
Open an existing PPT document as shown below −
File file = new File("C://POIPPT//Examples//example1.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file));
Get the spdes using the getSpdes() method as shown below −
List<XSLFSpde> spdes = ppt.getSpdes();
Select a spde from the array of the spdes, and change the order using the setSpdeOrder() method as shown below −
//selecting the fourth spde XSLFSpde selectesdspde = spdes.get(4); //bringing it to the top ppt.setSpdeOrder(selectesdspde, 1);
Given below is the complete program to reorder the spdes in a presentation −
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import org.apache.poi.xslf.usermodel.XMLSpdeShow; import org.apache.poi.xslf.usermodel.XSLFSpde; pubpc class ReorderSpde { pubpc static void main(String args[]) throws IOException { //opening an existing presentation File file = new File("example1.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file)); //get the spdes List<XSLFSpde> spdes = ppt.getSpdes(); //selecting the fourth spde XSLFSpde selectesdspde = spdes.get(13); //bringing it to the top ppt.setSpdeOrder(selectesdspde, 0); //creating an file object FileOutputStream out = new FileOutputStream(file); //saving the changes to a file ppt.write(out); out.close(); } }
Save the above Java code as ReorderSpde.java, and then compile and execute it from the command prompt as follows −
$javac ReorderSpde.java $java ReorderSpde
It will compile and execute to generate the following output.
Reordering of the spdes is done
Given below is the snapshot of the presentation before reordering the spdes −
After reordering the spdes, the presentation appears as follows. Here we have selected the spde with image and moved it to the top.
Deleting Spdes
You can delete the spdes using the removeSpde() method. Follow the steps given below to delete spdes.
Open an existing presentation using the XMLSpdeShow class as shown below −
File file = new File("C://POIPPT//Examples//image.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file));
Delete the required spde using the removeSpde() method. This method accepts an integer parameter. Pass the index of the spde that is to be deleted to this method.
ppt.removeSpde(1);
Given below is the program to delete spdes from a presentation −
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xslf.usermodel.XMLSpdeShow; pubpc class Deletespde { pubpc static void main(String args[]) throws IOException { //Opening an existing spde File file = new File("image.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file)); //deleting a spde ppt.removeSpde(1); //creating a file object FileOutputStream out = new FileOutputStream(file); //Saving the changes to the presentation ppt.write(out); out.close(); } }
Save the above Java code as Deletespde.java, and then compile and execute it from the command prompt as follows −
$javac Deletespde.java $java Deletespde
It will compile and execute to generate the following output −
reordering of the spdes is done
The snapshot below is of the presentation before deleting the spde −
After deleting the spde, the presentation appears as follows −
Advertisements