Page 1 of 1

delete a slide

PostPosted: Thu Apr 26, 2012 10:55 am
by oscar.novillo
Does anyone know how to delete a slide?

I've tried this, but i think i've got to delete from somewhere else.

Iterator it = pMLPackage.getParts().getParts().keySet().iterator();

PartName sl1 = null;
while (it.hasNext()) {
PartName p = (PartName);
if (p.getName().equals("/ppt/slides/slide1.xml")) {
sl1 = p;



Re: delete a slide

PostPosted: Thu Apr 26, 2012 10:46 pm
by jason
As you will see if you run your pptx through PartsList, slides are referenced in presentation.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting

    <p:sldId id="256" r:id="rId2"/>
    <p:sldId id="257" r:id="rId3"/>

Parsed in 0.001 seconds, using GeSHi

so you need to remove the relevant p:sldId entry, and the corresponding relationship from MainPresentationPart's relationship part.

Part /ppt/presentation.xml is class containing JaxbElement org.pptx4j.pml.Presentation

The removePart method works recursively, which is probably what you want for a docx, but isn't for a pptx (since slides reference a layout which in turn references a master, which then references all layouts, and you won't want to delete all of them).

So instead, use the lower level removeRelationship method, and remove the actual part, as you have done.

So, in outline:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                MainPresentationPart presentation = presentationMLPackage.getMainPresentationPart();
                // First, delete the slide
                SldIdLst sldIdLst = presentation.getJaxbElement().getSldIdLst();
                // .. etc
                // Second, delete the rel
                RelationshipsPart rels = presentation.getRelationshipsPart();
                rels.removeRelationship // etc
                // Also, delete the specified part from the package.
Parsed in 0.015 seconds, using GeSHi

Re: delete a slide

PostPosted: Fri Apr 27, 2012 10:05 am
by oscar.novillo
now its working

thanks a lot,