Search code examples
javaapache-poidocx

How to read alt text of image in word document Apache POI


Is there any way to store/edit altText of an image with Apache POI?

Like this on Microsoft Word: ms-word

I tried to find proper function, but nothing inside of the XWPFPictureData object related to altText.

java-code

Am I missing something or I have to cast XWPFPictureData to another class which is it has access to altText of image?


Solution

  • We found this from XWPFPicture's properties. Like this.

    for (XWPFParagraph paragraph : docx.getParagraphs()) {
        for (XWPFRun run : paragraph.getRuns()) {
            for (XWPFPicture embeddedPicture : run.getEmbeddedPictures()) {
                String description = embeddedPicture.getDescription();
                // Something
            }
        }
    }