Adding and image to XSLFTextRun using Apache POI

47 views Asked by At

I am using Apache POI to add an XSLFTable dynamically to a slide, the XSLFTable can contains text and images. In docx file extension I can successfully add images to XWPFRun using following code.

    public void replaceXWPFRunImagePlaceholder(XWPFRun run, FormLetterImageField image) {
        String path = image.getFile().getAbsolutePath();
        String[] imagePathArray = path.split(IMAGE_PATH_DELIMITER);
        String imageExtension = imagePathArray[imagePathArray.length-1];
        
        //Adding picture to the paragraph's run.
        try {           
            imageInputStream = new FileInputStream(image.getFile().getAbsolutePath());
            run.addPicture(imageInputStream, getPictureType(imageExtension), path, Units.toEMU(image.getWidth()), Units.toEMU(image.getHeight()));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

I am trying to achieve the same functionality using XSLFTextRun but it doesn't contains an addPicture() function to add an image to XSLFTextRun. Can anyone please guide me how can I add an image dynamically to an XSLFTable cell using XSLFTextRun or by using any other approach? Thanks.

0

There are 0 answers