Last active
April 20, 2021 02:24
-
-
Save aspose-com-gists/fc1c4560980079d14345c92c5765f0ab to your computer and use it in GitHub Desktop.
Working with Shapes in PowerPoint presentations using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Examples for working with Shapes in PowerPoint presentations using C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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