Slide Master cloning from one presentation to another is not working properly

Hi ,

My requirement is create target presentation which contains layout[master] from different presentation.Using addClone method i am able to add master slide but formatting is not proper

public static void addAllSlide(Presentation presentation,ApplicationContext Context)
throws JsonParseException, JsonMappingException, IOException {

List<Slide> packSlideCollection = presentation.getPackSlideCollection();
int packSlideCollectionSize = packSlideCollection.size();

IPresentation iPresentation = presentation.getiPresentation();

ISlideCollection iSlideCollection = iPresentation.getSlides();
IGlobalLayoutSlideCollection iLayoutSlideCollection = iPresentation.getLayoutSlides();
iLayoutSlideCollection.removeUnused();

HashMap<String, IMasterSlide> masterList=new  HashMap<>();

for (Entry<String, IMasterSlide> entry : MasterLayout.getAllMasterSlide().entrySet()) {
	
	
	IMasterSlide iMasterSlide=iPresentation.getMasters().addClone(entry.getValue());
	masterList.put(entry.getKey(), iMasterSlide);
	
}


for (int i = 0; i < packSlideCollectionSize; i++) {

    Slide slide = packSlideCollection.get(i);

    // Add new Slide to Presentation.
 
    ILayoutSlide layoutSlide = MasterLayout.getLayoutSlide(slide.getTemplateName(), slide.getLayoutSlideIndex());
    IMasterSlide iMasterSlide = masterList.get(slide.getTemplateName());
    
    ILayoutSlide  iLayoutSlide= iPresentation.getLayoutSlides().addClone(layoutSlide,iMasterSlide);
    
    ISlide isSlide = iSlideCollection.addEmptySlide(iLayoutSlide);
    
    try {
		
    	// Insert Slide Data.
		isSlide = SlideHelper.insertSlideData(slide, isSlide);
		
	} catch (Exception e) {

			
		log.error("Error occurred while creating slide.."+e);

	}



}

}

please find attached ppt. licensed java version -17.8. java
layout_26_09_2017_13_52_10_0.zip (171.2 KB)

@akshayshinde,

I have observed your requirement and sample code shared by you. Unfortunately, I am unable to use the sample code shared by you as it contains calls to custom functions on your end. Please share a working sample code that we may use on your end along with generated presentation and desired output presentation on your end.

Hi,

Please find the below code and attached ppt.

template.zip (311.2 KB)

	IPresentation iPresentation = new com.aspose.slides.Presentation();
	
	
	IPresentation iPresentation1 = new com.aspose.slides.Presentation("C:\\Users\\Desktop\\template\\Templates-1.pptx");
	IPresentation iPresentation2 = new com.aspose.slides.Presentation("C:\\Users\\Desktop\\template\\Templates-2.pptx");
	IPresentation iPresentation3 = new com.aspose.slides.Presentation("C:\\Users\\Desktop\\template\\Templates-3.pptx");
	
	IMasterSlide  iMasterSlide1=iPresentation1.getMasters().get_Item(0);
	IMasterSlide  iMasterSlide2=iPresentation2.getMasters().get_Item(0);
	IMasterSlide  iMasterSlide3=iPresentation3.getMasters().get_Item(0);
	
	IGlobalLayoutSlideCollection  iGlobalLayoutSlideCollection1=iPresentation1.getLayoutSlides();
	IGlobalLayoutSlideCollection  iGlobalLayoutSlideCollection2=iPresentation2.getLayoutSlides();
	IGlobalLayoutSlideCollection  iGlobalLayoutSlideCollection3=iPresentation3.getLayoutSlides();
	
	IMasterSlideCollection  iMasterSlideCollection=iPresentation.getMasters();
	IMasterSlide  iMasterSlide11=iMasterSlideCollection.addClone(iMasterSlide1);
	IMasterSlide iMasterSlide22 =iMasterSlideCollection.addClone(iMasterSlide2);
	IMasterSlide  iMasterSlide33=iMasterSlideCollection.addClone(iMasterSlide3);
	
	ILayoutSlide iLayoutSlide1=iPresentation.getLayoutSlides().addClone(iGlobalLayoutSlideCollection1.get_Item(0), iMasterSlide11);
	ILayoutSlide iLayoutSlide2=iPresentation.getLayoutSlides().addClone(iGlobalLayoutSlideCollection2.get_Item(0), iMasterSlide22);
	ILayoutSlide iLayoutSlide3=iPresentation.getLayoutSlides().addClone(iGlobalLayoutSlideCollection3.get_Item(0), iMasterSlide33);
	
	ISlide isSlide1 = iPresentation.getSlides().addEmptySlide(iLayoutSlide1);
	ISlide isSlide2 = iPresentation.getSlides().addEmptySlide(iLayoutSlide2);
	ISlide isSlide3 = iPresentation.getSlides().addEmptySlide(iLayoutSlide3);
	
	iPresentation.getLayoutSlides().removeUnused();
	
	iPresentation.save("C:\\Users\\Desktop\\New folder\\test.pptx", SaveFormat.Pptx);

@akshayshinde,

Thank you for sharing the information with us. I like to share that default Presentation object sets the default slide size of 720 x 540. However, the presentations that you are trying to clone to target presentation have bigger slide size. Therefore, when you clone them in target presentation, the content of cloned slide get stretched out of slides. You need to set the target presentation slide size to maximum slide size of all source presentations you are using. This way you will get correct rendering of content inside cloned slides. I suggest you to please add following modification on your end before cloning slides in your presentation.

iPresentation.getSlideSize().setSize((float)iPresentation1.getSlideSize().getSize().getWidth(),(float)iPresentation1.getSlideSize().getSize().getHeight(),SlideSizeScaleType.EnsureFit);

Hi ,

I tried this but it didn’t solve my problem.

@akshayshinde,

Please observe the generated presentation on my end. Can you please observe this and share what is issue in this and what is expected output that you want obtain. As requested earlier, please share the desired output presentation file for reference as well.

test.zip (123.1 KB)

Hi ,

iPresentation.getSlideSize().setSize((float)iPresentation1.getSlideSize().getSize().getWidth(),(float)iPresentation1.getSlideSize().getSize().getHeight(),SlideSizeScaleType.DoNotScale);

the bove code works for me.Thanks

@akshayshinde,

You are welcome. Please share, if I may help you further in this regard.