Connector
Contents
[
Hide
]
Shows how to connect shapes with connectors and change their targets using Aspose.Slides for PHP via Java.
Add a Connector
Insert a connector shape between two points on the slide.
function addConnector() {
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$connector = $slide->Shapes->addConnector(ShapeType::BentConnector2, 0, 0, 100, 100);
$presentation->save("connector.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}
Access a Connector
Retrieve the first connector shape added to a slide.
function accessConnector() {
$presentation = new Presentation("connector.pptx");
try {
$slide = $presentation->getSlides()->get_Item(0);
// Access the first connector on the slide.
$firstConnector = null;
$shapeCount = java_values($slide->getShapes()->size());
for ($index = 0; $index < $shapeCount; $index++) {
$shape = $slide->getShapes()->get_Item($index);
if (java_instanceof($shape, new JavaClass("com.aspose.slides.Connector"))) {
$firstConnector = $shape;
break;
}
}
} finally {
$presentation->dispose();
}
}
Remove a Connector
Delete a connector from the slide.
function removeConnector() {
$presentation = new Presentation("connector.pptx");
try {
$slide = $presentation->getSlides()->get_Item(0);
// Assuming the first shape on the slide is a connector.
$connector = $slide->getShapes()->get_Item(0);
$slide->getShapes()->remove($connector);
$presentation->save("connector_removed.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}
Reconnect Shapes
Attach a connector to two shapes by assigning start and end targets.
function reconnectShapes() {
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$shape1 = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 0, 0, 50, 50);
$shape2 = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 100, 100, 50, 50);
$connector = $slide->getShapes()->addConnector(ShapeType::BentConnector2, 0, 0, 100, 100);
$connector->setStartShapeConnectedTo($shape1);
$connector->setEndShapeConnectedTo($shape2);
$presentation->save("shapes_reconnected.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}