Page 1 of 1

Images not getting added in slides

PostPosted: Tue Dec 27, 2022 3:09 am
by quimperval
Hello
I'm following the sample InsertPicture.java for inserting images in slides, a different image per slide but the same image is displayed in all the slides.

I'm doing that inside a for loop I placed the code for generating the BinaryPartAbstractImage, a new object in each interation, the same with slides (for the slides I'm not assigning the part name when creating the objects, as I do that when inserting the slides with images in the presentation at the end of the process).
For each image I create a Pic object and then insert it to the shapes list as shown below.
Code: Select all
for(String fileName: files){
    final BinartPartAbstractImage image =
            BinaryPartAbstractImage.createImage(mlPackage, slide, new File(fileName));
    String relId = image.getRels().get(0).getId();
     Map<String,String> imageData = new HashMap<String, String>();
   
    imageData.put("id1", 0);
    imageData.put("descr", fileName);
    imageData.put("rEmbedId", relId);
    imageData.put("offx",Long.toString(offsetX));
    imageData.put("offy), Long.toString(offsetY));
    imageData.put("extcx", Long.toString(cX));
    imageData.put("extcy", Long.toString(cY));
    final Object pic =
    XmlUtils.unmarshallFromTemplate(SAMPLE_PICTURE,
        imageData, Context.jcPML, Pic.class);
    slide.getJaxbElement().getCsld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(pic);
}


I'm using String relId = image.getRels().get(0).getId() as the method in the sample ( getSourceRelationship().getId() ) is already deprecated.
What I've noticed is the
Relationship r = image.getRels().get(0);
For each file has the same data,
Id: rId2
Target: ../media/slide1_image_rId2.png

And when adding the image the logger shows the message overriding existing part /ppt/media/slide1_image_rId2.png.

Could that indicate that I have to set the part name of a slide when creating the slide?

Re: Images not getting added in slides

PostPosted: Tue Dec 27, 2022 4:17 am
by quimperval
Hello.

The answer to my question is yes, for having a different image per slide each it is necessary to set the part name of the slide when creating the object, in that way the image part is not being override every time.