# Manage ActiveX Controls in Presentations Using PHP

> Learn how Aspose.Slides for PHP via Java leverages ActiveX to automate and enhance PowerPoint presentations, giving developers powerful control over slides.

Source: https://docs.aspose.com/slides/php-java/activex/
Updated: 2026-08-13


## **Introduction**

ActiveX controls are used in presentations. Aspose.Slides for PHP via Java allows you to add and manage ActiveX controls, but they are a bit trickier to manage when compared to normal presentation shapes. We implemented support for adding Media Player Active control in Aspose.Slides. Note that ActiveX controls are not shapes; they are not part of the presentation's [ShapeCollection](https://reference.aspose.com/slides/php-java/aspose.slides/shapecollection/). They are part of the separate [ControlCollection](https://reference.aspose.com/slides/php-java/aspose.slides/controlcollection/) instead. In this topic, we will show you how to work with them.

## **Add a Media Player ActiveX Control to a Slide**
To add an ActiveX Media Player control, do this:

1. Create an instance of the [Presentation](https://reference.aspose.com/slides/php-java/aspose.slides/presentation) class and generate an empty presentation instance.
1. Access the target slide in [Presentation](https://reference.aspose.com/slides/php-java/aspose.slides/presentation).
1. Add the Media Player ActiveX control using the [addControl](https://reference.aspose.com/slides/php-java/aspose.slides/controlcollection/addcontrol/) method exposed by [ControlCollection](https://reference.aspose.com/slides/php-java/aspose.slides/controlcollection/).
1. Access the Media Player ActiveX control and set the video path by using its properties.
1. Save the presentation as a PPTX file.

This sample code, based on the steps above, shows to how to add Media Player ActiveX Control to a slide:

```php
  # Create empty presentation instance
  $pres = new Presentation();
  try {
    # Adding the Media Player ActiveX control
    $pres->getSlides()->get_Item(0)->getControls()->addControl(ControlType::WindowsMediaPlayer, 100, 100, 400, 400);
    # Access the Media Player ActiveX control and set the video path
    $pres->getSlides()->get_Item(0)->getControls()->get_Item(0)->getProperties()->set_Item("URL", "Wildlife.wmv");
    # Save the Presentation
    $pres->save("Output.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }
```

## **Modify an ActiveX Control**
{{% alert color="info" %}} 

Aspose.Slides for PHP via Java 7.1.0 and newer versions are equipped with components for managing ActiveX controls. You can access the already added ActiveX control in your presentation and modify or delete it through its properties.

{{% /alert %}} 

To manage a simple ActiveX control like a text box and simple command button on a slide, do this:

1. Create an instance of the [Presentation](https://reference.aspose.com/slides/php-java/aspose.slides/presentation) class and load the presentation with ActiveX controls in it.
1. Obtain a slide reference by its index.
1. Access the ActiveX controls in the slide by accessing the [ControlCollection](https://reference.aspose.com/slides/php-java/aspose.slides/controlcollection/).
1. Access the TextBox1 ActiveX control using the [Control](https://reference.aspose.com/slides/php-java/aspose.slides/control/) object.
1. Change the properties of the TextBox1 ActiveX control that include text, font, font height, and frame position.
1. Access the second access control called CommandButton1.
1. Change the button caption, font, and position.
1. Shift the position of the ActiveX controls frames.
1. Write the modified presentation to a PPTX file.

This sample code, based on the steps above, shows how to manage a simple ActiveX control: 

```php
  # Accessing the presentation with ActiveX controls
  $pres = new Presentation("ActiveX.pptm");
  try {
    # java.awt classes are reached through the PHP/Java bridge
    $bufferedImageClass = new JavaClass("java.awt.image.BufferedImage");
    $fontClass = new JavaClass("java.awt.Font");
    $systemColor = new JavaClass("java.awt.SystemColor");
    # Accessing the first slide in presentation
    $slide = $pres->getSlides()->get_Item(0);
    # changing TextBox text
    $control = $slide->getControls()->get_Item(0);
    if (!java_is_null($control->getName()->equalsIgnoreCase("TextBox1") && $control->getProperties())) {
      $newText = "Changed text";
      $control->getProperties()->set_Item("Value", $newText);
      # Changing substitute image. PowerPoint will replace this image during activeX activation,
      # so sometime it's OK to leave image unchanged.
      $image = new Java("java.awt.image.BufferedImage", $control->getFrame()->getWidth(), $control->getFrame()->getHeight(), $bufferedImageClass->TYPE_INT_ARGB);
      $graphics = $image->getGraphics();
      $graphics->setColor($systemColor->window);
      $graphics->fillRect(0, 0, $image->getWidth(), $image->getHeight());
      $font = new Java("java.awt.Font", $control->getProperties()->get_Item("FontName"), $fontClass->PLAIN, 16);
      $graphics->setColor($systemColor->windowText);
      $graphics->setFont($font);
      $graphics->drawString($newText, 10, 20);
      $graphics->setColor($systemColor->controlShadow);
      $graphics->drawLine(0, $image->getHeight() - 1, 0, 0);
      $graphics->drawLine(0, 0, $image->getWidth() - 1, 0);
      $graphics->setColor($systemColor->controlDkShadow);
      $graphics->drawLine(1, $image->getHeight() - 2, 1, 1);
      $graphics->drawLine(1, 1, $image->getWidth() - 2, 1);
      $graphics->setColor($systemColor->controlHighlight);
      $graphics->drawLine(1, $image->getHeight() - 1, $image->getWidth() - 1, $image->getHeight() - 1);
      $graphics->drawLine($image->getWidth() - 1, $image->getHeight() - 1, $image->getWidth() - 1, 1);
      $graphics->setColor($systemColor->controlLtHighlight);
      $graphics->drawLine(0, $image->getHeight(), $image->getWidth(), $image->getHeight());
      $graphics->drawLine($image->getWidth(), $image->getHeight(), $image->getWidth(), 0);
      $graphics->dispose();
      $baos = new Java("java.io.ByteArrayOutputStream");
      Java("javax.imageio.ImageIO")->write($image, "PNG", $baos);
      $control->getSubstitutePictureFormat()->getPicture()->setImage($pres->getImages()->addImage($baos->toByteArray()));
    }
    # Changing Button caption
    $control = $pres->getSlides()->get_Item(0)->getControls()->get_Item(1);
    if (!java_is_null($control->getName()->equalsIgnoreCase("CommandButton1") && $control->getProperties())) {
      $newCaption = "Show MessageBox";
      $control->getProperties()->set_Item("Caption", $newCaption);
      # Changing substitute
      $image = new Java("java.awt.image.BufferedImage", $control->getFrame()->getWidth(), $control->getFrame()->getHeight(), $bufferedImageClass->TYPE_INT_ARGB);
      $graphics = $image->getGraphics();
      $graphics->setColor($systemColor->control);
      $graphics->fillRect(0, 0, $image->getWidth(), $image->getHeight());
      $font = new Java("java.awt.Font", $control->getProperties()->get_Item("FontName"), $fontClass->PLAIN, 16);
      $graphics->setColor($systemColor->windowText);
      $graphics->setFont($font);
      $metrics = $graphics->getFontMetrics($font);
      $graphics->drawString($newCaption, $image->getWidth() - $metrics->stringWidth($newCaption) / 2, 20);
      $graphics->setColor($systemColor->controlLtHighlight);
      $graphics->drawLine(0, $image->getHeight() - 1, 0, 0);
      $graphics->drawLine(0, 0, $image->getWidth() - 1, 0);
      $graphics->setColor($systemColor->controlHighlight);
      $graphics->drawLine(1, $image->getHeight() - 2, 1, 1);
      $graphics->drawLine(1, 1, $image->getWidth() - 2, 1);
      $graphics->setColor($systemColor->controlShadow);
      $graphics->drawLine(1, $image->getHeight() - 1, $image->getWidth() - 1, $image->getHeight() - 1);
      $graphics->drawLine($image->getWidth() - 1, $image->getHeight() - 1, $image->getWidth() - 1, 1);
      $graphics->setColor($systemColor->controlDkShadow);
      $graphics->drawLine(0, $image->getHeight(), $image->getWidth(), $image->getHeight());
      $graphics->drawLine($image->getWidth(), $image->getHeight(), $image->getWidth(), 0);
      $graphics->dispose();
      $baos = new Java("java.io.ByteArrayOutputStream");
      Java("javax.imageio.ImageIO")->write($image, "PNG", $baos);
      $control->getSubstitutePictureFormat()->getPicture()->setImage($pres->getImages()->addImage($baos->toByteArray()));
    }
    # moving 100 points down
    foreach($pres->getSlides()->get_Item(0)->getControls() as $ctl) {
      $frame = $ctl->getFrame();
      $ctl->setFrame(new ShapeFrame($frame->getX(), $frame->getY() + 100, $frame->getWidth(), $frame->getHeight(), $frame->getFlipH(), $frame->getFlipV(), $frame->getRotation()));
    }
    $pres->save("withActiveX-edited_java.pptm", SaveFormat::Pptm);
    # removing controls
    $pres->getSlides()->get_Item(0)->getControls()->clear();
    $pres->save("withActiveX-cleared_java.pptm", SaveFormat::Pptm);
  } catch (JavaException $e) {
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }
```

## **FAQ**

### Does Aspose.Slides preserve ActiveX controls when reading and re-saving if they cannot be executed in the Java runtime?

Yes. Aspose.Slides treats them as part of the presentation and can read/modify their properties and frames; executing the controls themselves is not required to preserve them.

### How do ActiveX controls differ from OLE objects in a presentation?

ActiveX controls are interactive managed controls (buttons, text boxes, media player), whereas [OLE](/slides/php-java/manage-ole/) refers to embedded application objects (for example, an Excel worksheet). They are stored and handled differently and have different property models.

### Do ActiveX events and VBA macros work if the file has been modified by Aspose.Slides?

Aspose.Slides preserves the existing markup and metadata; however, events and macros run only inside PowerPoint on Windows when security allows it. The library does not execute VBA.



## Related articles

- [ActiveX](https://docs.aspose.com/slides/php-java/examples/elements/activex/)