I try to go through a word document and save all the images found in the word document. I tried uploading a sample word document to an online demo and noticed that the 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 moving a document?
Currently, I am getting all the text from the document as follows:
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;
}
}
birdy source
share