1

I'm working with PowerPoint template. I'm trying to fill it with data in specific placeholders. I don't have any problem with placing text:

for (XSLFShape sh : slide.getShapes()) {
    String name = sh.getShapeName();
    String placeholderName = export.getPlaceholderName();
    if (sh instanceof XSLFTextShape && name.equalsIgnoreCase(placeholderName)) {
        XSLFTextShape txShape = (XSLFTextShape) sh;
        txShape.clearText();
        txShape.setText(parsedText);
    }
}

I'm not able to add image to existing anchor. What I found is that first I have to collect shape data with anchor

for (XSLFShape sh : slide.getShapes()) {
    String name = sh.getShapeName();
    String placeholderName = export.getPlaceholderName();
    if (sh instanceof XSLFPictureShape) {
        XSLFPictureShape shape = (XSLFPictureShape) sh;
        String shapeName = shape.getShapeName();
        removeShape.setShapeName(shapeName);
        removeShape.setAnchor(shape.getAnchor());
        removeShape.setShape(shape);
}

}

and then add picture with anchor collected data and remove original.

XSLFPictureData pd = ppt.addPicture(removeShape.getPictureData(), PictureData.PictureType.PNG);
XSLFPictureShape pic = slide.createPicture(pd);
pic.setAnchor(removeShape.getAnchor());
slide.removeShape(removeShape.getShape());

Is there any easier way to add image to placeholder image on template? enter image description here

adi
  • 31
  • 5
  • Seems to be a duplicate of https://stackoverflow.com/questions/35721547/how-to-add-image-to-image-placeholder-added-in-pptx-using-apache-poi-api – Johannes Rabauer Feb 03 '23 at 10:36

0 Answers0