Merge/Clone Slides to new Presentaion

When I try and merge/clone multiple ASPPS files genereated from Microsoft Reporting Serverices using Aspose.Slides for Reporting Services the output gets all messed up. I use Aspose Slides for .net to merged the outputs.

I know the reports that are genereated from Reporting Services are OK because I can export them individually which I have included in this thread.

I have attached 3 samples that where created. 2 of them where just using reporting services the other was merged using aspose slides for .net after reporting services created them.

DMTest1.ppt - Created using Aspose Slides for Reporting Services
DMTest2.ppt - Created using Aspose Slides for Reporting Services
DMTest3Merged.ppt - Created using Aspose Slides for Reporting Services and then merged the 2 reports using Aspose Slides for .net.

Below is the code I use to merge the Power point presentations.

public static byte[] MergePPT(IList lstBytes)
{
if (lstBytes == null)
throw new ArgumentNullException("MergePPT: lstBytes is null");

if (lstBytes.Count == 0)
return null;

if (lstBytes.Count == 1)
return lstBytes[0];

Presentation newPPT = new Presentation();

foreach(byte[] pptStream in lstBytes)
{
Presentation pres = new Presentation(new MemoryStream(pptStream));
foreach (Slide pptSlide in pres.Slides)
newPPT.CloneSlide(pptSlide, newPPT.Slides.LastSlidePosition + 1);
}

newPPT.Slides.RemoveAt(0); //This removes the empty slide that is created when you crete the Presentation object
MemoryStream ms = new MemoryStream();
newPPT.Save(ms, Aspose.Slides.Export.SaveFormat.Ppt);
return ms.ToArray();
}

I am getting closer to getting the output correct. I have modified the code to look like this. When I run it using the below code I get most of the report merged and outputed correctly.

The issue I am facing now is formatting. Is there a way to set the orientation of the slide and fit the content into the slide without it spilling over?

Presentation pres1 = new Presentation(@"C:\AsposeSlidesError\DMTest1.ppt");
Presentation pres2 = new Presentation(@"C:\AsposeSlidesError\DMTest2.ppt");
Presentation newPPT = new Presentation();
SortedList s = new SortedList();

for (int slides = 0; slides < pres1.Slides.LastSlidePosition; slides++)
{
pres1.CloneSlide(pres1.Slides[slides], newPPT.Slides.LastSlidePosition + 1, newPPT, s);
}
for (int slides = 0; slides < pres2.Slides.LastSlidePosition; slides++)
{
pres2.CloneSlide(pres2.Slides[slides], newPPT.Slides.LastSlidePosition + 1, newPPT, s);
}

newPPT.Slides.RemoveAt(0);
newPPT.Save(@"C:\AsposeSlidesError\MergeTest.ppt", Aspose.Slides.Export.SaveFormat.Ppt);

Hello Darren,

I’m sorry for inconvenience.

Your code example is correct. There is another problem. Microsoft PowerPoint doesn’t allow create slides with different size and orientation in one presentation. So for correct merging both presentations should have the same slide size.

One small addition. You should use separate SortedList for the second “for”. There should be used unique SortedList for each source/destination pair of ppt presentation.

Thanks Alexy..

I made the changes you suggested and forced our users to only run reports with the same orientation and everything is working great...

Here is the code sample for merging multiple PowerPoint presentations. If you have any suggestions please let me know... I think this would be a good example to include in your documentation.
Thanks for the help...

public static byte[] MergePPT(IList lstBytes)
{
if (lstBytes == null)
throw new ArgumentNullException("MergePPT: lstBytes is null");

if (lstBytes.Count == 0)
return null;

if (lstBytes.Count == 1)
return lstBytes[0];

Presentation newPPT = null;

foreach(byte[] pptStream in lstBytes)
{
if (newPPT == null)
newPPT = new Presentation(new MemoryStream(pptStream));
else
{
SortedList s = new SortedList();
Presentation pres = new Presentation(new MemoryStream(pptStream));

for (int slides = 0; slides < pres.Slides.LastSlidePosition; slides++)
{
pres.CloneSlide(pres.Slides[slides], newPPT.Slides.LastSlidePosition + 1, newPPT, s);
}
}
}

MemoryStream ms = new MemoryStream();
newPPT.Save(ms, Aspose.Slides.Export.SaveFormat.Ppt);
return ms.ToArray();
}