Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/fc1c4560980079d14345c92c5765f0ab to your computer and use it in GitHub Desktop.
Save aspose-com-gists/fc1c4560980079d14345c92c5765f0ab to your computer and use it in GitHub Desktop.
Working with Shapes in PowerPoint presentations using C++
Examples for working with Shapes in PowerPoint presentations using C++
// File paths
const String sourceFilePath = u"SourceDirectory\\SamplePresentation4.pptx";
const String outputFilePath = u"OutputDirectory\\AddConnectedShapesPresentation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Get the first slide
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
// Add the first shape
SharedPtr<IAutoShape> ellipse = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 150, 150, 50);
// Add the second shape
SharedPtr<IAutoShape> rectangle = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 100, 300, 100, 100);
// Add the connector
SharedPtr<IConnector> connector = slide->get_Shapes()->AddConnector(ShapeType::BentConnector2, 0, 0, 10, 10);
// Join the shapes with the connector
connector->set_StartShapeConnectedTo(ellipse);
connector->set_EndShapeConnectedTo(rectangle);
// Call reroute to set the automatic shortest path between shapes
connector->Reroute();
// Save Presentation file
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\SamplePresentation4.pptx";
const String outputFilePath = u"OutputDirectory\\AddShapePresentation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Get the first slide
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
// Add the shape
SharedPtr<IAutoShape> ellipse = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 150, 150, 50);
// Save Presentation file
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\ShapePresentation2.pptx";
const String outputFilePath = u"OutputDirectory\\CloneShapePresentation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Access first slide
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
// Accessing shapes collection for the selected slide
SharedPtr<IShapeCollection> sourceShapes = slide->get_Shapes();
// Get shape collection from destination slide
SharedPtr<ISlide> destSlide = presentation->get_Slides()->idx_get(1);
SharedPtr<IShapeCollection> destShapes = destSlide->get_Shapes();
// Clone shape
destShapes->InsertClone(0, sourceShapes->idx_get(1), 50, 150);
// Save Presentation file
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\ShapePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\RemoveShapePresentation.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Access first slide
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
String alttext = u"User Defined";
int iCount = slide->get_Shapes()->get_Count();
for (int i = 0; i < iCount; i++)
{
// Access the shape
SharedPtr<Shape> ashape = DynamicCast<Aspose::Slides::Shape>(slide->get_Shapes()->idx_get(i));
if (String::Compare(ashape->get_AlternativeText(), alttext, StringComparison::Ordinal) == 0)
{
// Remove the shape
slide->get_Shapes()->Remove(ashape);
}
}
// Save Presentation file
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment