Merge Presentation - C++ PowerPoint API

Presentation Merging

When you merge one presentation to another, you are effectively combining their slides in a single presentation to obtain one file.

What Can Be Merged

With Aspose.Slides, you can merge

  • entire presentations. All the slides from the presentations end up in one presentation
  • specific slides. Selected slides end up in one presentation
  • presentations in one format (PPT to PPT, PPTX to PPTX, etc) and in different formats (PPT to PPTX, PPTX to ODP, etc) to one another.

Merging Options

You can apply options that determine whether

  • each slide in the output presentation retains a unique style
  • a specific style is used for all the slides in the output presentation.

To merge presentations, Aspose.Slides provides AddClone methods (from the ISlideCollection interface). There are several implementations of the AddClone methods that define the presentation merging process parameters. Every Presentation object has a Slides collection, so you can call a AddClone method from the presentation to which you want to merge slides.

The AddClone method returns an ISlide object, which is a clone of the source slide. The slides in an output presentation are simply a copy of the slides from the source. Therefore, you can make changes the resulting slides (for example, apply styles or formatting options or layouts) without worrying about the source presentations becoming affected.

Merge Presentations

Aspose.Slides provides the AddClone (ISlide) method that allows you to combine slides while the slides retain their layouts and styles (default parameters).

This C++ code shows you how to merge presentations:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (const auto& slide : pres2->get_Slides())
{
    pres1->get_Slides()->AddClone(slide);
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

Merge Presentations with Slide Master

Aspose.Slides provides the AddClone (ISlide, IMasterSlide, bool) method that allows you to combine slides while applying a slide master presentation template. This way, if necessary, you get to change the style for slides in the output presentation.

This code in C++ demonstrates the described operation:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (const auto& slide : pres2->get_Slides())
{
    pres1->get_Slides()->AddClone(slide, pres2->get_Masters()->idx_get(0), true);
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

If you want the slides in the output presentation to have a different slide layout, use the AddClone (ISlide, ILayoutSlide) method instead when merging.

Merge Specific Slides From Presentations

This C++ code shows you how to select and combine specific slides from different presentations to get one output presentation:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (const auto& slide : pres2->get_Slides())
{
    pres1->get_Slides()->AddClone(slide, pres2->get_LayoutSlides()->idx_get(0));
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

Merge Presentations With Slide Layout

This C++ code shows you how to combine slides from presentations while applying your preferred slide layout to them to get one output presentation:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (const auto& slide : pres2->get_Slides())
{
    pres1->get_Slides()->AddClone(slide, pres2->get_LayoutSlides()->idx_get(0));
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

Merge Presentations With Different Slide Sizes

To merge 2 presentations with different slide sizes, you have to resize one of the presentations to make its size match that of the other presentation.

This sample code demonstrates the described operation:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres1Size = pres1->get_SlideSize()->get_Size();

auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
pres2->get_SlideSize()->SetSize(pres1Size.get_Width(), pres1Size.get_Height(), SlideSizeScaleType::EnsureFit);

for (const auto& slide : pres2->get_Slides())
{
    pres1->get_Slides()->AddClone(slide);
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

Merge Slides to Presentation Section

This C++ code shows you how to merge a specific slide to a section in a presentation:

auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (int32_t index = 0; index < pres2->get_Slides()->get_Count(); index++)
{
    auto slide = pres2->get_Slides()->idx_get(index);
    pres1->get_Slides()->AddClone(slide, pres1->get_Sections()->idx_get(0));
}

pres1->Save(u"combined.pptx", SaveFormat::Pptx);

The slide is added at the end of the section.