Hay,
I’m trying to duplicate a slide in a PPTM (or PPTX doesn’t matter).
My first try was:
-Find the slide I want to duplicate
-Add the slide to the MainPresentationPart
But I just got errors over errors - probably because it’s not possible to add a slide with same rid’s and so on.
Anyway my second attempt looks like this:
-Find the slide(1) I want to duplicate
-Get the slides(1) SlideLayoutPart
-Get the slides(1) Sld ( getContents() )
-Deepcopy slide(1)
-Create a new slide(2) SlidePart (new SlidePart(partName) )
-Add the slide(2) to the MainPresentationPart
-Add the SlideLayoutPart of slide(1) to slide(2)
-Add the deepCopy of slide(1) to slide(2)
This works much better - also without errors. But theres another problem. The duplicated slide(2) doesn’t have any content like backgroundimages or other images but it has all the shapes and all the textboxes of slide(1). So the slide is duplicated without its mediafiles it needs.
I don’t see wheres my problem. Probably someone here is able to see whats wrong with my code.
Kind Regards.
P.S.: Here is my code:
//Slide I want to duplicate
SlidePart slide = presentationPart.getSlide(1);
SlideLayoutPart layoutPart = slide.getSlideLayoutPart();
Sld jaxbElement = slide.getContents();
JAXBContext jaxbContext = slide.getJAXBContext();
Sld deepCopy = XmlUtils.deepCopy(jaxbElement, jaxbContext);
//tempCount counts the numbers of slides
SlidePart newSlide = new SlidePart(new PartName("/ppt/slides/slide"
+ tempCount + ".xml"));
tempCount++;
presentationPart.addSlide(newSlide);
newSlide.addTargetPart(layoutPart);
newSlide.setContents(deepCopy);