Attach 3 images in single slide at specified positions using Apache POI XSLF

前端 未结 1 1688
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 12:01

I need to paste 3 pictures in single slide using Apache POI XSLF. However I could able to add only one picture in a slide. Also I could not find any ways to specify the size and

1条回答
  •  深忆病人
    2021-01-23 12:30

    You nead to set Anchor to your pictures

    for (int i = 1; i <= 2; i++) {
        byte[] pictureData = IOUtils.toByteArray(new FileInputStream(
                "C:\\Users\\Ashok\\Pictures\\" + i + ".png"));
        int elementIndex = ppt.addPicture(pictureData,
                XSLFPictureData.PICTURE_TYPE_PNG);
        XSLFPictureShape picture = slide.createPicture(elementIndex);
    
        // Set picture position and size
        picture.setAnchor(new Rectangle(positionX, positionY, width, height));
    
        List allPictures = ppt.getAllPictures();
        System.out.println(allPictures.size());
    }
    

    0 讨论(0)
提交回复
热议问题