I'm trying to traverse through a word document and save all the images found in the word document. I tried uploading the sample word document to the online demo and noticed that images are listed as:
/word/media/image1.png rId5 image/png
/word/media/image2.png rId5 image/png
/word/media/image3.jpg rId5 image/jpeg
How can I programmatically save these images while traversing the document?
Currently I get all the text from the document like this:
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filePath))
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart()
Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement()
Body body = wmlDocumentEl.getBody();
DocumentTraverser traverser = new DocumentTraverser();
class DocumentTraverser extends TraversalUtil.CallbackImpl {
@Override
public List<Object> apply(Object o) {
if (o instanceof org.docx4j.wml.Text) {
....
}
return null;
}
}