Page 1 of 1

Problems duplicating a slide

PostPosted: Wed Aug 27, 2014 9:29 pm
by RobBy
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);

Re: Problems duplicating a slide

PostPosted: Fri Aug 29, 2014 9:19 am
by jason
Duplicating a slide is non-trivial; it is one of the things the MergePptx component of Plutext's Enterprise edition can help you with.

That said, have a look at the diagram on p85 of Wouter's "Open XML Explained" book (the first page of the PresentationML chapter). Google for a link to the free eBook/PDF. That picture shows the links you'll need to preserve.

Also, I suggest you use docx4j 3.2.0, since there are a couple of things in there which will save you from having to worry about subtle details.

Re: Problems duplicating a slide

PostPosted: Fri Aug 29, 2014 11:31 pm
by RobBy
Thanks for your reply.

I'm already using docx4j 3.2.0 beta2.

I've also managed to duplicate a slide. I just forgot to add the relationships to the new slide.

EDIT: Ahh I see - docx4j 3.2.0 final release is up now. Will use that - thanks.