Group Shapes in PowerPoint in Java

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)

● 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);



Sharing Java Code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store