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?