Page 1 of 1

replace an image in the pptx?

PostPosted: Fri Jul 01, 2011 3:23 pm
by Jim
I will play with the PartsList again tomorrow with fresher eyes, but I have yet to find these relationships (/ppt/slides/_rels/slideX.xml.rels)...

Let me ask a higher-level question: I have a "placeholder" image in a powerpoint "template" that I am loading with data on the fly.
What is the best way to replace an image in the pptx? I'm thinking that I need these mid-level relationships to tie the slide to the image part within the pptx, so I know which image to replace; I have not crossed the bridge of having to replace that image--will that be possible? Or is that even the best way?

Thanks,
Jim

Re: replace an image in the pptx?

PostPosted: Thu Jul 07, 2011 1:27 am
by jason
As with a docx, there are 2 ways to do it.

Approach 1: keep existing image part

The first way is to keep the existing image part, and replace its contents. On this approach the existing rel is kept.

This approach may be best if the new image is of the same type (ie png, jpeg etc), and the dimensions etc will be the same (specified in the slide - if the dimensions etc will be different, you'll need to generate new XML for the slide)

Approach 2: replace image part

The second way is to delete the image part, and the rel pointing to it, and add a new image part and a new rel.

There is a docx4j sample which takes this second approach, called AddImage. (We don't currently have a pptx4j equivalent in svn - maybe someone reading has one they can post? pptx-java-f14/adding-images-to-a-generated-powerpoint-document-t319.html is superseded now; createImagePart now takes a OpcPackage).

See further docx-java-f6/replacing-images-in-doc-t523.html