Need to Apply Master Layout of One PPTX to Another PPTX in C#

HI,

I’m trying to apply master layout from template PPT to PPT2 using below code but my content placeholder is positioned as per PPT2 position which should have been as per the template PPT :

using Aspose.Slides;
using Aspose.Slides.Export;

var ps1 = new Presentation(PPTXpath);
var t = new Presentation(templatePath);

while (t.Slides.Count > 0)
{
    t.Slides.RemoveAt(0);
}

// master slide
var ms = t.Masters[0];
foreach (var slide in ps1.Slides)
{
    t.Slides.AddClone(slide,ms,false);
}

t.Save(targetpath, SaveFormat.Pptx);

Please let me know wht might be the issue

@u.mirashi

To apply the master layout from one PowerPoint presentation to another using Aspose.Slides, you need to ensure that you are correctly cloning the master slide and applying it to the slides in the destination presentation. The issue you are facing, where the content placeholder positions are based on the destination presentation instead of the template, may arise from not properly associating the cloned master slide with the slides you are adding.

Here’s a revised version of your code that demonstrates how to clone the master slide from the template presentation and apply it to the slides in the target presentation:

using Aspose.Slides;
using Aspose.Slides.Export;

// Load the source and template presentations
var sourcePresentation = new Presentation(sourcePath);
var templatePresentation = new Presentation(templatePath);

// Clear existing slides in the template presentation
while (templatePresentation.Slides.Count > 0)
{
    templatePresentation.Slides.RemoveAt(0);
}

// Clone the master slide from the template presentation
IMasterSlide clonedMasterSlide = templatePresentation.Masters[0];

// Iterate through each slide in the source presentation
foreach (var slide in sourcePresentation.Slides)
{
    // Clone the slide and associate it with the cloned master slide
    var clonedSlide = templatePresentation.Slides.AddClone(slide, clonedMasterSlide, true);
}

// Save the modified presentation
templatePresentation.Save(targetPath, SaveFormat.Pptx);

Key Points:

  1. Cloning the Master Slide: Ensure you clone the master slide from the template presentation before adding the slides from the source presentation.
  2. Associating Slides with the Master: When adding cloned slides, specify the cloned master slide to ensure that the layout is applied correctly.
  3. Saving the Presentation: Finally, save the modified presentation to the desired path.

This approach should help you maintain the layout as per the template presentation. If you continue to experience issues, please double-check the structure of your template and source presentations to ensure they are compatible.

For more detailed examples and documentation, you can refer to the Aspose documentation on working with master slides and layouts.

Sources:
[1]: CloneToAnotherPresentationWithMaster.cs

Tried the code but same issue,
but the position of the placeholder in target file is different than its master layout
attaching screenshots
Position of the placeholder
image.png (166.4 KB)

Position of placeholder in master
image.png (99.2 KB)

@u.mirashi,
We need more details to investigate the case. Please share the following files and information:

  • sample presentation files
  • Aspose.Slides version you are using