Ellipse

Create Ellipse

To add a simple ellipse to a selected slide of the presentation, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add an AutoShape of Ellipse type using addAutoShape method exposed by IShapeCollection object.
  • Write the modified presentation as a PPTX file.

In the example given below, we have added an ellipse to the first slide

  # Instantiate Presentation class that represents the PPTX
  $pres = new Presentation();
  try {
    # Get the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # Add AutoShape of ellipse type
    $sld->getShapes()->addAutoShape(ShapeType::Ellipse, 50, 150, 150, 50);
    # Write the PPTX file to disk
    $pres->save("EllipseShp1.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Create Formatted Ellipse

To add a better formatted ellipse to a slide, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add an AutoShape of Ellipse type using addAutoShape method exposed by IShapeCollection object.
  • Set the Fill Type of the Ellipse to Solid.
  • Set the Color of the Ellipse using SolidFillColor.Color property as exposed by FillFormat object associated with the IShape object.
  • Set the Color of the lines of the Ellipse.
  • Set the Width of the lines of the Ellipse.
  • Write the modified presentation as a PPTX file.

In the example given below, we have added a formatted ellipse to the first slide of the presentation.

  # Instantiate Presentation class that represents the PPTX
  $pres = new Presentation();
  try {
    # Get the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # Add AutoShape of ellipse type
    $shp = $sld->getShapes()->addAutoShape(ShapeType::Ellipse, 50, 150, 150, 50);
    # Apply some formatting to ellipse shape
    $shp->getFillFormat()->setFillType(FillType::Solid);
    $shp->getFillFormat()->getSolidFillColor()->setColor(new java("java.awt.Color", PresetColor->Chocolate));
    # Apply some formatting to the line of Ellipse
    $shp->getLineFormat()->getFillFormat()->setFillType(FillType::Solid);
    $shp->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $shp->getLineFormat()->setWidth(5);
    # Write the PPTX file to disk
    $pres->save("EllipseShp1.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }