java使用aspose读取word里的图片
依赖
<dependency><groupId>com.techCoLtd</groupId><artifactId>aspose-words-16.4.0-jdk16</artifactId><classifier>jdk16</classifier> </dependency>
/*** 获取图片并返回图片集合*/ public static List<String> getPic() throws Exception {List<String> picList = new ArrayList<>();Document doc = new Document(saveFilePath);NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);int imageIndex = 0;for (Shape shape : (Iterable<Shape>) shapes) {if (shape.hasImage()) {//word中的图片 可能有各种各样的格式//使用FileFormatUtil.imageTypeToExtension 方法 可以自动提取格式String imageFileName = "D:\\work\\output\\" + imageIndex + FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType());FileUtil.mkParentDirs(imageFileName);//自动创建父级目录try {shape.getImageData().save(imageFileName);} catch (Exception e) {e.printStackTrace();}imageIndex++;picList.add(imageFileName);}}return picList; }