Page 1 of 1

How to Remove image from pptx

PostPosted: Wed Aug 22, 2012 3:23 am
by sramanandi
We have placeholder images in a pptx file that we replace dynamically at runtime with real images.. However for some reason if we dont want have an image for a particular placeholder we wants to remove that placeholder image from the pptx file. How do I go about removing the image from the pptx ?

Thanks

Re: How to Remove image from pptx

PostPosted: Wed Aug 22, 2012 7:26 pm
by jason
2 steps:
1. find the reference to the image on the slide; note its rel Id, then delete it all
2. remove the relationship with that relId, and, if the image is not being used by any other rel, the image part

From the SlidePart you can get its RelationshipsPart. That contains a method getRelationshipByID(String id)

Then you can either removePart(PartName partName), or just removeRelationship(Relationship rel)

Run your pptx through the PartsList sample to understand the structure better.

Re: How to Remove image from pptx

PostPosted: Wed Aug 22, 2012 7:32 pm
by sramanandi
Thanks for reply jason,

Yeah I have been able to remove the image successfully..

What I did
- Inspect the xml to finder the element Id for the Pic element,
- In java Get reference to the Pic element
- And then mainPart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().removeAll(referenceToPicElementToRemove)

I did not touch relationships, I dont mind the image media and relationship being there in pptx as long as it is not displayed