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/02b8b90a3b1b53e565530346be710916 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/02b8b90a3b1b53e565530346be710916 to your computer and use it in GitHub Desktop.
Merge PowerPoint Presentations using C#
// Instantiate a Presentation object that represents a target presentation file
using (Presentation presentation1 = new Presentation("presentation1.pptx"))
{
// Instantiate a Presentation object that represents a source presentation file
using (Presentation presentation2 = new Presentation("presentation2.pptx"))
{
// Merge only even slides of presentation2 (first slide is at 0 index)
for (int i = 1; i <= presentation2.Slides.Count; i = i + 2)
{
presentation1.Slides.AddClone(presentation2.Slides[i]);
}
}
presentation1.Save("merged-presentation-even.pptx", Export.SaveFormat.Pptx);
}
// Instantiate a Presentation object that represents a target presentation file
using (Presentation presentation1 = new Presentation("presentation1.pptx"))
{
// Instantiate a Presentation object that represents a source presentation file
using (Presentation presentation2 = new Presentation("presentation2.pptx"))
{
// Merge first two slides only using slide master
presentation1.Slides.AddClone(presentation2.Slides[0], presentation1.Masters[0], true);
presentation1.Slides.AddClone(presentation2.Slides[1], presentation1.Masters[0], true);
}
presentation1.Save("merged-presentation-master.pptx", Export.SaveFormat.Pptx);
}
// Instantiate a Presentation object that represents a target presentation file
using (Presentation presentation1 = new Presentation("presentation1.pptx"))
{
// Instantiate a Presentation object that represents a source presentation file
using (Presentation presentation2 = new Presentation("presentation2.pptx"))
{
foreach (ISlide slide in presentation2.Slides)
{
// Merge slides from source to target
presentation1.Slides.AddClone(slide);
}
}
// Save the presentation
presentation1.Save("merged-presentation.pptx", Export.SaveFormat.Pptx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment