Dear Jens,
We are sorry for the delayed response but we were working on your query.
Since you have mentioned that it was hard for you to share your presentation data, so we would appreciate, if you could share the stack trace of the exception and may be it proves helpful for us to identify the problem.
You can use one master for cloned slides in destination presentation. For this please use changeMaster method merging slides to one presentation. I have modified the source code provided by you and hopefully it will work as I have tested it with my presentation data. I have also attached the source and resultant PPT files for your reference.
Last parameter of cloneSlide method contains TreeMap as argument, which is used by Aspose.Slides internally for holding shapes identifiers. It should be unique for each source-target presentations pair. So if you clone several slides from one source presentation to one target presentation and use the same TreeMap for that then only one master slide will be copied for all cloned slides. If you use unique TreeMap for each clone operation then new copy of master slide will be copied for each cloned slide.
static Slide appendCopyOfSlideToReport(Slide sourceSlide, Presentation targetReport)
{
// now copy this slide to the result object
long mainMasterId = targetReport.getSlideByPosition(1).getMasterId();
Slide MasterSld=targetReport.getSlideById(mainMasterId);
int targetSlidePosition = targetReport.getSlides().getLastSlidePosition() + 1; // the position where new slide should be inserted
int slideWidth = sourceSlide.getBackground().getWidth();
int slideHeight = sourceSlide.getBackground().getHeight();
Point targetSize = targetReport.getSlideSize();
if (targetSize.getX() < slideHeight)
{
targetReport.setSlideSize(new Point(slideWidth, slideHeight));
}
boolean isFromDifferentPresentation = sourceSlide.getParent() != targetReport;
// TODO:2: java.util.TreeMap idList - Is an access to control the masters here?
Slide destSlide = sourceSlide.getParent().cloneSlide(sourceSlide, targetSlidePosition, targetReport, new TreeMap());
if (sourceSlide.getNotes() != null && sourceSlide.getNotes().getText() != null)
{
Notes destNotes = destSlide.getNotes();
if (destSlide.getNotes() == null)
{
destNotes = destSlide.addNotes();
}
destNotes.setText(sourceSlide.getNotes().getText());
}
// TODO:1: attach Master from target presentation?, setMaster's visibility?
if (/*isFromDifferentPresentation &&*/ mainMasterId != 0L)
{
destSlide.changeMaster(MasterSld,true);
}
//inheritHeadersFootersVisibility(sourceSlide, destSlide);
return destSlide;
}
Thanks and Regards,