Group Shapes in PowerPoint in Java

Andrew Wilson
1 min readMay 20, 2022

In PowerPoint, if you want to add a shape that is not included in the default shape library, you can group shapes to create custom shapes that meet your requirements. In this article, you will learn how to programmatically group shapes in a PowerPoint document using Free Spire.Presentation for Java.

Import JAR Dependency (2 Methods)

● Download the free library and unzip it, and then add the Spire.Presentation.jar file to your project as dependency.

● You can also add the jar dependency to your maven project by adding the following configurations to the pom.xml.


Sample Code

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

public class GroupShapes {
public static void main(String[] args) throws Exception {
//Create a PowerPoint document
Presentation ppt = new Presentation();
//Get the first slide
ISlide slide = ppt.getSlides().get(0);

//Add a rectangle shape to the slide
IShape rectangle = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(20,100,200,40));

//Add a ribbon shape to the slide
IShape ribbon = slide.getShapes().appendShape(ShapeType.RIBBON_2, new Rectangle2D.Double(60, 75, 120, 80));

//Add the shapes to a list
ArrayList list = new ArrayList();

//Group the shapes

//Save the resultant document
ppt.saveToFile("GroupShapes.pptx", FileFormat.PPTX_2013);



Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.