I've been trying to read all content (including tables, pictures, paragraphs) from a word document. I'm able to read tables and paragraphs using getBodyElementsIterator() but it doesn't read pictures present inside the document.
Although I'm able to read pictures seperately using getAllPictures() but I need to read everything in order.
I've tried looking for XWPFPicture instance while looping inside getBodyElementsIterator() but I'm not able to find any image instance.
Iterator<IBodyElement> iter = xdoc.getBodyElementsIterator();
while (iter.hasNext()) {
IBodyElement elem = iter.next();
if (elem instanceof XWPFParagraph) {
System.out.println("para - "+elem.getClass());
} else if (elem instanceof XWPFTable) {
System.out.println("table - "+elem);
} else if (elem instanceof XWPFPictureData){
System.out.println("picture - "+elem);
} else {
System.out.println("else - "+elem);
}
}
This is the output I'm getting.
paraorg.apache.poi.xwpf.usermodel.XWPFParagraph@4d3167f4
paraorg.apache.poi.xwpf.usermodel.XWPFParagraph@ed9d034
tableorg.apache.poi.xwpf.usermodel.XWPFTable@6121c9d6
paraorg.apache.poi.xwpf.usermodel.XWPFParagraph@87f383f
paraorg.apache.poi.xwpf.usermodel.XWPFParagraph@4eb7f003
It contains paragraphs and tables but not any pictures
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…