Add, Connect, Remove, or Clone PowerPoint Shapes in Java

Work with PowerPoint shapes in Java

Shapes in PowerPoint presentations are used to elaborate a particular point or create diagrams such as flowcharts, etc. Moreover, the inclusion of shapes makes the presentation more appealing. Therefore, PowerPoint provides a number of shapes such as line, ellipse, rectangle, etc. In this article, you will learn how to automate the manipulation of shapes in PowerPoint presentations. Particularly, the article will cover how to add, connect, clone, or remove shapes in PowerPoint presentations using Java.

Java API to Work with PowerPoint Shapes

In order to work with PowerPoint shapes, we’ll use Aspose.Slides for Java. It is a powerful Java API that lets you manipulate PowerPoint presentations seamlessly. Particularly, the API allows you to create, modify, read, and convert the presentation documents. You can either download the API or get it installed using the following Maven configuration.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>21.3</version>
    <classifier>jdk16</classifier>
</dependency>

Types of PowerPoint Shapes

PowerPoint supports a variety of shapes that you can add to the presentation slides. Accordingly, Aspose.Slides for Java supports the following shape types:

Add Shape to PowerPoint Slides in Java

Aspose.Slides for Java provides ShapeType class to specify the type of shape you want to add. The following are the steps to add a particular shape in a PowerPoint presentation using Java.

The following code sample shows how to add a shape to a PowerPoint presentation using Java.

The following is the output you will get after executing this code.

Add PowerPoint shape in Java

Add Connector between PowerPoint Shapes using Java

The connector is a line that is used to join two shapes. Moreover, a connector could be a straight or a curved line. The following are the steps to add a connector between two PowerPoint shapes.

The following code sample shows how to add connector between two shapes in PowerPoint using Java.

The following is the screenshot of the PowerPoint presentation after connecting the shapes.

Connect PowerPoint shapes in Java

Clone a PowerPoint Shape using Java

You can also clone a PowerPoint shape to create its copy. The following are the steps to perform this operation.

The following code sample shows how to add clone of a PowerPoint shape using Java.

Remove Shapes from PowerPoint Slides in Java

You can also remove the PowerPoint shapes from a slide using Aspose.Slides for Java. The following are the steps to remove a PowerPoint shape from the shape collection.

The following code sample shows how to remove a PowerPoint shape from a slide using Java.

Get a Free API License

You can get a free temporary license in order to use the API without evaluation limitations.

Conclusion

In this article, you have learned how to work with shapes in PowerPoint presentations using Java. Particularly, you have seen how to add, connect, remove or clone the PowerPoint shapes. Furthermore, you can explore more about the API by consulting its documentation. Also, in case of any queries, feel free to let us know via our forum.

See Also