Group Presentation Shapes in PHP

Add a Group Shape

Aspose.Slides support working with group shapes on slides. This feature helps developers support richer presentations. Aspose.Slides for PHP via Java supports adding or accessing group shapes. It is possible to add shapes to an added group shape to populate it or access any property of group shape. To add a group shape to a slide using Aspose.Slides for PHP via Java:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of a slide by using its Index
  3. Add a group shape to the slide.
  4. Add the shapes to the added group shape.
  5. Save the modified presentation as a PPTX file.

The example below adds a group shape to a slide.

  # Instantiate Presentation class
  $pres = new Presentation();
  try {
    # Get the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # Accessing the shape collection of slides
    $slideShapes = $sld->getShapes();
    # Adding a group shape to the slide
    $groupShape = $slideShapes->addGroupShape();
    # Adding shapes inside Added group shape
    $groupShape->getShapes()->addAutoShape(ShapeType::Rectangle, 300, 100, 100, 100);
    $groupShape->getShapes()->addAutoShape(ShapeType::Rectangle, 500, 100, 100, 100);
    $groupShape->getShapes()->addAutoShape(ShapeType::Rectangle, 300, 300, 100, 100);
    $groupShape->getShapes()->addAutoShape(ShapeType::Rectangle, 500, 300, 100, 100);
    # Adding group shape frame
    $groupShape->setFrame(new ShapeFrame(100, 300, 500, 40, NullableBool::False, NullableBool::False, 0));
    # Write the PPTX file to disk
    $pres->save("GroupShape.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Access the AltText Property

This topic shows simple steps, complete with code examples, for adding a group shape and accessing AltText property of group shapes on slides. To access AltText of a group shape in a slide using Aspose.Slides for PHP via Java:

  1. Instantiate Presentation class that represents PPTX file.
  2. Obtain the reference of a slide by using its Index.
  3. Accessing the shape collection of slides.
  4. Accessing the group shape.
  5. Accessing the AlternativeText property.

The example below accesses alternative text of group shape.

  # Instantiate Presentation class that represents PPTX file
  $pres = new Presentation("AltText.pptx");
  try {
    # Get the first slide
    $sld = $pres->getSlides()->get_Item(0);
    for($i = 0; $i < java_values($sld->getShapes()->size()) ; $i++) {
      # Accessing the shape collection of slides
      $shape = $sld->getShapes()->get_Item($i);
      if (java_instanceof($shape, new JavaClass("com.aspose.slides.GroupShape"))) {
        # Accessing the group shape.
        $grphShape = $shape;
        for($j = 0; $j < java_values($grphShape->getShapes()->size()) ; $j++) {
          $shape2 = $grphShape->getShapes()->get_Item($j);
          # Accessing the AltText property
          echo($shape2->getAlternativeText());
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

FAQ

Is nested grouping (a group inside a group) supported?

Yes. GroupShape has a getParentGroup method, which directly indicates hierarchy support (a group can be a child of another group).

How do I control the group’s z-order relative to other objects on the slide?

Use the GroupShape’s getZOrderPosition method to inspect its position in the display stack.

Can I prevent moving/editing/ungrouping?

Yes. The group’s lock section is exposed via GroupShapeLock, which lets you restrict operations on the object.