Hi Anita,
Let me try to explain what you are doing while cloning master slides and what is
CloneSlide method doing on back end. The masters collections have multiple masters slides in
MasterCollection. Now, the
CloneSlide method clone the respective master slide for the cloned slide as well. So, when you clone the sllide in master slide collection, the master slide along with its master get cloned. That is why you are getting a lot of masters in cloned presentation. Moreover, there is no way to identify the duplicated or repeated master slides. Please visit
thread link 2 for your reference.
Now, I will share the correct approach that you must follow. Suppose, there are N masters in your source presentation. You need to create N normal slides of each of master type. By doing so, you will use slides for SlideCollection and clone them in target presentation. This way all the respective masters will also get cloned in target presentation. Now, you can remove all unused masters and then remove the cloned slides afterwards. The cloned slide will get removed but their masters will retain in target presentation.
String path = @"C:\Documents";
Presentation pres = new Presentation(path+“MulltiMaster.ppt”);
Presentation presTarget = new Aspose.Slides.Presentation();
System.Collections.SortedList sList = new System.Collections.SortedList();
Aspose.Slides.Slide slide=null ;
//The approach to clone master from source to destination presentation is that
//we need to have slide of each master type in source presentation.
//We will clone the slides in destination presentation and it will clone the master as well
for(int i=0;i<pres.Slides.Count ;i++)
{
slide = pres.Slides[i];
pres.CloneSlide(slide, presTarget.Slides.LastSlidePosition+1, presTarget, sList);
}
//Here we are removing default slide that is created in presTarget
//The reason for deleting this slide is to free the default master of presTarget
// and then deleting all unused masters
presTarget.Slides.RemoveAt(0);
presTarget.DeleteUnusedMasters();
//Now we need to add an empty slide as there must be one minimum slide in presentation
presTarget.AddEmptySlide();
// Here we are removing all the cloned slides that we cloned for masters. It will keep the masters
//That is resultant
int lastSlide=presTarget.Slides.LastSlidePosition;
for (int i = 0; i < lastSlide-1; i++)
{
presTarget.Slides.RemoveAt(0);
}
//Saving presentation
presTarget.Write(path + “MulltiMaster_New.ppt”);
Many Thanks,