Aspose.Slides for Python via .
When merging slides with the same slide master layout, duplicate layouts are added to the slide master.
For example, this happens when you write code like the following
import aspose.slides as slides
with slides.Presentation("Presentation1.pptx") as pres1: as slides.
with slides.Presentation("Presentation2.pptx") as pres2:
for slide in pres2.slides:
pres1.slides.add_clone(slide)
pres1.save("combined.pptx", slides.export.SaveFormat.PPTX)
pres1 and pres2 have the same slide master.
How can I prevent duplicates of the same slide master from appearing?
When cloning a slide from one presentation to another, the layout and master slides related to the slide are also copied. Unfortunately, Aspose.Slides cannot prevent the duplication you described. You can read the name and type of layouts (the name and layout_type properties in the LayoutSlide class respectively), compare them with other layout slides and remove duplications. You can use a similar way for master slides.
In addition, you can remove unused layout and master slides as follows:
@yuhino,
Yes, you can change the layout of a slide by the layout name. The following code example shows you how to do this.
import aspose.slides as slides
slide_index = 1
layout_name = "MyLayout" # for example
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[slide_index]
new_layout_slide = next((s for s in presentation.layout_slides if s.name == layout_name), None)
if new_layout_slide is not None:
slide.layout_slide = new_layout_slide
presentation.save("output.pptx", slides.export.SaveFormat.PPTX)