You can get a count of the number of shapes used in a presentation using the method getShapeName() of the XSLFShape class. Given below is the program to read the shapes from a presentation −

    1. import java.io.File;
    2. import java.io.FileInputStream;
    3. import java.io.FileOutputStream;
    4. import java.io.IOException;
    5.  
    6. import org.apache.poi.xslf.usermodel.XMLSlideShow;
    7. import org.apache.poi.xslf.usermodel.XSLFShape;
    8. import org.apache.poi.xslf.usermodel.XSLFSlide;
    9.  
    10. public class ReadingShapes {
    11.  
    12. public static void main(String args[]) throws IOException {
    13.  
    14. //creating a slideshow
    15. File file = new File(“shapes.pptx”);
    16. XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(file));
    17.  
    18. //get slides
    19. XSLFSlide[] slide = ppt.getSlides();
    20.  
    21. //getting the shapes in the presentation
    22. System.out.println(“Shapes in the presentation:”);
    23. for (int i = 0; i < slide.length; i++){
    24.  
    25. XSLFShape[] sh = slide[i].getShapes();
    26. for (int j = 0; j < sh.length; j++){
    27.  
    28. //name of the shape
    29. System.out.println(sh[j].getShapeName());
    30. }
    31. }
    32.  
    33. FileOutputStream out = new FileOutputStream(file);
    34. ppt.write(out);
    35. out.close();
      }
    36. }

    Save the above Java code as ReadingShapes.java, and then compile and execute it from the command prompt as follows −

    1. $javac ReadingShapes.java
    2. $java ReadingShapes

    It will compile and execute to generate the following output.

    1. Shapes in the presentation:
    2. Rectangle 1
    3. Oval 1
    4. Isosceles Triangle 1

    The newly added slide with the various shapes appears as follows −

    ReadingShapes.jpg