Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 13, 2021 10:58
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/3fbb5a14be693e49be410ae57cf50d56 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/3fbb5a14be693e49be410ae57cf50d56 to your computer and use it in GitHub Desktop.
Merge PowerPoint Slides using C++
Merge PowerPoint Slides using C++
// The path to the documents directory.
const String sourceFilePath1 = u"SourceDirectory\\SamplePresentation2.pptx";
const String sourceFilePath2 = u"SourceDirectory\\SamplePresentation3.pptx";
const String outputFilePath = u"OutputDirectory\\mergedPresentation.pptx";
// Instantiate Presentation class
SharedPtr<Presentation> presentation1 = MakeObject<Presentation>(sourceFilePath1);
SharedPtr<Presentation> presentation2 = MakeObject<Presentation>(sourceFilePath2);
for (SharedPtr<ISlide> slide : presentation2->get_Slides())
{
// Merge slides from source to destination
presentation1->get_Slides()->AddClone(slide);
}
// Save the presentation
presentation1->Save(outputFilePath, SaveFormat::Pptx);
// The path to the documents directory.
const String sourceFilePath1 = u"SourceDirectory\\SamplePresentation.pptx";
const String sourceFilePath2 = u"SourceDirectory\\SamplePresentation3.pptx";
const String outputFilePath = u"OutputDirectory\\mergedPresentation.pptx";
// Load the presentation files
SharedPtr<Presentation> presentation1 = MakeObject<Presentation>(sourceFilePath1);
SharedPtr<Presentation> presentation2 = MakeObject<Presentation>(sourceFilePath2);
// Merge the first slide using slide master
presentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(0), presentation1->get_Masters()->idx_get(0), true);
// Save the presentation
presentation1->Save(outputFilePath, SaveFormat::Pptx);
// The path to the documents directory.
const String sourceFilePath1 = u"SourceDirectory\\SamplePresentation2.pptx";
const String sourceFilePath2 = u"SourceDirectory\\SamplePresentation3.pptx";
const String outputFilePath = u"OutputDirectory\\mergedPresentation.pptx";
// Load the presentation files
SharedPtr<Presentation> presentation1 = MakeObject<Presentation>(sourceFilePath1);
SharedPtr<Presentation> presentation2 = MakeObject<Presentation>(sourceFilePath2);
for (int i = 0; i < presentation2->get_Slides()->get_Count(); i++)
{
// Merge only even slides
if (i % 2 == 0)
{
presentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(i));
}
}
// Save the presentation
presentation1->Save(outputFilePath, SaveFormat::Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment