ShapeCollection — Aspose.Slides FOSS for Java API Reference

The ShapeCollection class represents the collection of shapes on a slide. It implements IShapeCollection and Iterable<IShape>.

Package: org.aspose.slides.foss

import org.aspose.slides.foss.*;
public class ShapeCollection implements IShapeCollection, Iterable<IShape>

Methods

Access

MethodReturnsDescription
get(int index)IShapeGet shape by zero-based index.
size()intNumber of shapes.
indexOf(IShape shape)intIndex of the given shape, or -1.
iterator()Iterator<IShape>Iterator over all shapes.

Add Shapes

MethodReturnsDescription
addAutoShape(ShapeType, double x, double y, double w, double h)IAutoShapeAdd an auto shape.
addAutoShape(ShapeType, double x, double y, double w, double h, boolean createFromTemplate)IAutoShapeAdd an auto shape with template option.
addConnector(ShapeType, double x, double y, double w, double h)IConnectorAdd a connector shape.
addPictureFrame(ShapeType, double x, double y, double w, double h, IPPImage image)IPictureFrameAdd a picture frame.
addTable(double x, double y, double[] colWidths, double[] rowHeights)ITableAdd a table.

Insert Shapes

MethodReturnsDescription
insertAutoShape(int index, ShapeType, double x, double y, double w, double h)IAutoShapeInsert an auto shape at the given index.
insertConnector(int index, ShapeType, double x, double y, double w, double h)IConnectorInsert a connector at the given index.
insertPictureFrame(int index, ShapeType, double x, double y, double w, double h, IPPImage image)IPictureFrameInsert a picture frame at the given index.
insertTable(int index, double x, double y, double[] colWidths, double[] rowHeights)ITableInsert a table at the given index.

Reorder

MethodReturnsDescription
reorderSingle(int newIndex, IShape shape)voidMove a shape to a new z-order position.

Usage Examples

Add Shapes to a Slide

import org.aspose.slides.foss.*;

Presentation prs = new Presentation();
ISlide slide = prs.getSlides().get(0);
IShapeCollection shapes = slide.getShapes();

IAutoShape rect = shapes.addAutoShape(ShapeType.RECTANGLE, 50, 50, 200, 100);
rect.addTextFrame("Rectangle");

IAutoShape ellipse = shapes.addAutoShape(ShapeType.ELLIPSE, 300, 50, 100, 100);

System.out.println("Shape count: " + shapes.size());
prs.save("shapes.pptx", SaveFormat.PPTX);

Add a Table

double[] colWidths = {100, 100, 100};
double[] rowHeights = {30, 30, 30};
ITable table = slide.getShapes().addTable(50, 200, colWidths, rowHeights);

See Also