Copying masters

Hi,


How can I copy ALL the masters from a source ppt to a new target ppt?

Note its ppt , and not pptx.

Also, I would like to keep the Master theme intact in the target ppt just like source.

If I try to CloneSlide ( master , targetPres)… it creates a NEW theme in the master collection for each sub-master in the source file…

I am using sortList…
Thanks.
anita

Hi Anita,


I have tried to understand the issue shared by you and like to share that master and normal slides are part of SlideCollection collectively in case of PPT. I will really appreciate if you may please share the source presentation with us along with the code snippet that you are using for cloning. Please also share the generated output along with the presentation highlighting what actually you want in resultant presentation.

Many Thanks,
Source code for copying MSTERS from one file to another file.

presTarget = new Aspose.Slides.Presentation();
pres = new Aspose.Slides.Presentation(pptFileName);
sList = new SortedList();

foreach (Aspose.Slides.Slide mstr in pres.Masters)
presTarget .CloneSlide(mstr, pres.Slides.LastSlidePosition, pres, sList);
presTarget.Write("test.ppt");

Use any ppt file containing several masters.. you will see the target ppt will contain more master sets than the source.


Hi Anita,


Please accept my apologies for delayed response. I have tried to clone masters on my end and they cloned fine without extra master sets. As requested earlier please share the source presentation along with generated output by highlighting the issue specified. Please also highlight the issue in the generated presentation as well.

We are sorry for your inconvenience,
Hi,

thanks for the response.

Could you please share the source code which you used to close masters from one ppt to another with me?

In addition, did you use Aspose.pptx or Aspose.ppt interface? I am using Aspose.Ppt interface. I tried 6.1.0 as well, same results.

You code would be of help. If that doesn't work, I will send you my sample code and ppts.

Thanks,
Anita

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,

Hi,

Please take a look at the Master slide view in PowerPoint of the source and target ppt. (attached). As you know, PowerPoint differentiates between THEMES and MASTERS within themes.

I used the exact code that you provided and ran a test run.

If you look at the source file you can see that it contains ONE SINGLE theme which contains 9 different masters, e.g., different ones for the title slide, a slide with text, a slide with graphics etc.

The resulting target file created by Aspose contains THREE themes, one for each of the slides in the source ppt. Within the themes all masters are the same.

Please let me know if you have any questions and if this can be fixed so the target file themes/masters look the same as in the source file? Thanks much!

source code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Slides;

namespace AsposeClone
{
class Program
{
static void Main(string[] args)
{
if (args.Count() < 2)
{
Console.Write(" need source and target ppt names ");
return;
}

String fileSource = args[0];
String fileTarget = args[1];
Presentation pres = new Presentation(fileSource);

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(fileTarget);

}
}
}

Hi Anita,


I have observed the requirements shared by you. Your presentation has one slide master but with different master themes inside that. I regret to share that the said support is not availble in case of Aspose.Slides and that is why it is creating differnt slides masters based on different master themes used in your source presetnation. An issue with ID SLIDESNET-33356 has been created in our issue tracking system to further investigate that whether this feature support is available or not. We will share the further information with you as soon as it will be available.

We are sorry for your inconvenience,