public void extractImagesFromDocx(byte[] docx) throws Exception {
Document document = new Document(new ByteArrayInputStream(docx));
NodeCollection<Shape> docShapes = (NodeCollection<Shape>) document.getChildNodes(NodeType.SHAPE, true);
int idx = 0;
for(Shape shape: docShapes) {
if(shape.hasImage()) {
String imageFileName = java.text.MessageFormat.format(
"Aspose.Images.{0}{1}", idx, FileFormatUtil
.imageTypeToExtension(shape.getImageData()
.getImageType()));
shape.getImageData().save(DIR+imageFileName);
idx++;
}
}
}
Drawing.SaveAllImages.1.png (8.6 KB)