Menu

Get Shapes from Presentation Slide

Shoaib

Get Shapes from Presentation Slide

Aspose.Slides

ISlide slide =  pres.getSlides().get_Item(0);

//Accessing source slide shape collection
IShapeCollection sourceShapes = slide.getShapes();

//Iterating through all shapes inside the slide
for (int i = 0; i < sourceShapes.size(); i++)
{
    System.out.println(sourceShapes.get_Item(i).getWidth() +  " x " + 
            sourceShapes.get_Item(i).getHeight());
}

Download

Apache POI SL

XSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++)
{
    XSLFShape[] sh = slide[i].getShapes();
    for (int j = 0; j < sh.length; j++)
    {
        // name of the shape
        String name = sh[j].getShapeName();

        // shapes's anchor which defines the position of this shape in
        // the slide
        java.awt.geom.Rectangle2D anchor = sh[j].getAnchor();

        if (sh[j] instanceof XSLFConnectorShape)
        {
            XSLFConnectorShape line = (XSLFConnectorShape) sh[j];
            System.out.println("Connector Shape.");
            // work with Line
        }
        else if (sh[j] instanceof XSLFTextShape)
        {
            XSLFTextShape shape = (XSLFTextShape) sh[j];
            System.out.println("Text Shape.");
            // work with a shape that can hold text
        }
        else if (sh[j] instanceof XSLFPictureShape)
        {
            XSLFPictureShape shape = (XSLFPictureShape) sh[j];
            System.out.println("Picture Shape.");
            // work with Picture
        }
    }
}

Download