Applying destination theme while cloning slides

Hi Team,

I have attached two pptx files (source and destination). I would like to write a code in Aspose.Slides which will replicate the operation of copying both the slides from the destination file to the source file and use the destination theme. I am using 7.1 and I know this is an old legacy api. But please help me out with the coding. I am not in a position to purchase the new license. I have tried to write the code but it is throwing an exception. Below is what I tried.

Aspose.Slides.License license = new Aspose.Slides.License();
license.SetLicense("Aspose.Total.lic");

PresentationEx source = new PresentationEx(@"C:\Sample Projects\formatPPT\formatPPT\Working\sourceSlide.pptx");
PresentationEx dest = new PresentationEx(@"C:\Sample Projects\formatPPT\formatPPT\Working\destSlide.pptx");

SlideEx destSlide = dest.Slides[0];
SlideExCollection slds = dest.Slides;
MasterSlideEx SourceMaster = destSlide.LayoutSlide.MasterSlide;
slds.AddClone(source.Slides[0], SourceMaster);

dest.Write(@"C:\Sample Projects\formatPPT\formatPPT\Working\Results\master.pptx");

Please help me out here.

Regards,
Nilotpal

Hi Nilotpal,

I have observed your requirements and have ported the shared sample code w.r.t to new API. Please try using the following sample code on your end to serve the purpose. Please share, if I may help you further in this regard.

public static void applytheme()
{
    Aspose.Slides.License license = new Aspose.Slides.License();
    // license.SetLicense("Aspose.Total.lic");
    String path = @"D:\Aspose Data";
    Presentation source = new Presentation(path +"sourceSlide.pptx");
    Presentation dest = new Presentation(path +"destSlide.pptx");

    ISlide destSlide = dest.Slides[0];

    ISlideCollection slds = dest.Slides;
    IMasterSlide SourceMaster = destSlide.LayoutSlide.MasterSlide;

    slds.AddClone(source.Slides[0], SourceMaster, true);

    dest.Save(path +"master.pptx", SaveFormat.Pptx);
}

Many Thanks,

Thanks for your reply. But this code will not work for Aspose.Slides 7.1 version. I am using the Aspose.Slides.Pptx namespace. Please help me out.

Hi Nilotpal,

I like to share that the requested version is no longer supported by Aspose.Slides and the legacy code shared by you has no issue in it. There is some issue with version using on your end with your deck of presentation and that is why you are getting the exception. However, when I have tried your presentation deck with latest Aspose.Slides for .NET 15.8.1, there is no issue. I request you to please consider upgrading to latest version as it comes with much more new features as compare to legacy API.

Many Thanks,

Hi Mudassir,

Thanks for your reply. My code did work finally. had something to do with the template it seems. But after cloning the formatting gets messed up. If I manually copy the slides from source to destination using destinatiion theme, the formatting does not get messed up, however, from code when I am doing it the positioning of the ppt controls are altered. Can you help me with that?

Regards,
Nilotpal

Hi Nilotpal,

That is good that by altering the template the code has started to work on your end. I may for sure help you in this regard but I will test your template with latest version and if there is any formatting issue, I will log the request in our issue tracking system. Otherwise, if there is no issue with new API, I will suggest you to please try using the latest version on your end.

Many Thanks,

Hi Mudassir,

Thank you for your reply. We have managed to purchase the latest version of Aspose.Slides for .Net, as you suggested. Now, my requirement is to copy slides from source.pptx and place it in dest.pptx and apply formatting of dest.pptx on the inserted slides. Below is the code that I have tried.

Presentation source = new Presentation(@"C:\Sample Projects\formatPPT\formatPPT\Working\source.pptx");
Presentation dest = new Presentation(@"C:\Sample Projects\formatPPT\formatPPT\Working\dest.pptx");

ISlide destSlide = dest.Slides[0];
ISlideCollection slds = dest.Slides;
IMasterSlide SourceMaster = destSlide.LayoutSlide.MasterSlide;

slds.AddClone(source.Slides[0], SourceMaster, true);
slds.AddClone(source.Slides[1], SourceMaster, true);
slds.AddClone(source.Slides[2], SourceMaster, true);
slds.AddClone(source.Slides[3], SourceMaster, true);
slds.AddClone(source.Slides[4], SourceMaster, true);
slds.AddClone(source.Slides[5], SourceMaster, true);
slds.AddClone(source.Slides[6], SourceMaster, true);
slds.AddClone(source.Slides[7], SourceMaster, true);

dest.Save(@"C:\Sample Projects\formatPPT\formatPPT\Working\Results\final.pptx", SaveFormat.Pptx);

However, the formatting of the final pptx file is getting messed up. I have attached the working pptx files (source and dest). Please let me know what is the issue here and help me out.

Regards,
Nilotpal

Hi Nilotpal,

I have observed your comments and like to share with you that the issue is occurring because the slide size is different in the presentations source.pptx and dest.pptx. I have made necessary changes in the code and the formatting is not messed up anymore. I have also attached the generated output presentation for your kind reference. Please use below code on your end to serve the purpose.

Presentation source = new Presentation(@"D:\source.pptx");
Presentation dest = new Presentation(@"D:\dest.pptx");

dest.SlideSize.Type = source.SlideSize.Type;
dest.SlideSize.Size = source.SlideSize.Size;

ISlide destSlide = dest.Slides[0];
ISlideCollection slds = dest.Slides;
IMasterSlide SourceMaster = destSlide.LayoutSlide.MasterSlide;

slds.AddClone(source.Slides[0], SourceMaster, true);
slds.AddClone(source.Slides[1], SourceMaster, true);
slds.AddClone(source.Slides[2], SourceMaster, true);
slds.AddClone(source.Slides[3], SourceMaster, true);
slds.AddClone(source.Slides[4], SourceMaster, true);
slds.AddClone(source.Slides[5], SourceMaster, true);
slds.AddClone(source.Slides[6], SourceMaster, true);
slds.AddClone(source.Slides[7], SourceMaster, true);

dest.Save(@"D:\test.pptx", SaveFormat.Pptx);

Please let us know if the issue persists. We will be happy to assist you further.

Best Regards,

Hi Adnan,

Thank you so much for your reply. However, there is still a formatting issue. The footer from the dest ppt file is rising up in the final ppt file. In your attached file test.pptx, if you check slide number 3, you will understand what I’m saying. Please help me out.

Regards,
Nilotpal

Hi Nilotpal,

I have observed your comments and like to share with you that the issue on slide number 3 is appearing because of the slide size in the presentation dest.pptx. Aspose.Slides is working as expected and there is not any issue. Please change the size of slide and adjust the footer on it so that the problem does not occur.

I hope this will clarify the concept. Please share if I may help you further in this regard.

Best Regards,

Hi Adnan,

I have attached both the files again, with some adjustments in their sizes, but still could not fix the issue. Please let me know how I could fix this.

Regards,
Nilotpal

Hi Nilotpal,

I have observed your comments and have re sized the slides for you. Now, slides are of the same size (see size.JPG). Please try using the attached presentations (dest.pptx & source (2).pptx) and the below code on your end to serve the purpose. I have also attached the generated output presentation for your kind reference (see CloneAllGood.pptx).

Presentation source = new Presentation(@"D:\source(2).pptx");
Presentation dest = new Presentation(@"D:\dest.pptx");

dest.SlideSize.Type = source.SlideSize.Type;
dest.SlideSize.Size = source.SlideSize.Size;

ISlide destSlide = dest.Slides[0];
ISlideCollection slds = dest.Slides;
IMasterSlide SourceMaster = destSlide.LayoutSlide.MasterSlide;

slds.AddClone(source.Slides[0], SourceMaster, true);
slds.AddClone(source.Slides[1], SourceMaster, true);
slds.AddClone(source.Slides[2], SourceMaster, true);
slds.AddClone(source.Slides[3], SourceMaster, true);
slds.AddClone(source.Slides[4], SourceMaster, true);
slds.AddClone(source.Slides[5], SourceMaster, true);
slds.AddClone(source.Slides[6], SourceMaster, true);
slds.AddClone(source.Slides[7], SourceMaster, true);

dest.Save(@"D:\CloneAllGood.pptx", SaveFormat.Pptx);

Please let us know if the issue persists. We will be happy to assist you further.

Best Regards,

Hi Adnan,

Thank you so much for all your detailed help. My issue is solved and I am good. Thanks again. Keep up the good work that you are doing.

Regards,
Nilotpal

Hi Nilotpal,

Thank you for your valuable feedback.

We are glad to know that your problem is resolved and things have started working on your end.

Please feel free to contact us if we could be of any help to you.

Best Regards,