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;
}
相关推荐
沉木渡香32 分钟前
VSCode中Java开发环境配置的三个层级(Windows版)1-3
java·windows·vscode
程序员小白条34 分钟前
度小满运维开发一面
java·运维·python·职场和发展·运维开发
Leo655356 小时前
JDK8 的排序、分组求和,转换为Map
java·开发语言
书源丶8 小时前
二十八、API之《System 类》——与系统交互的“桥梁”
java·交互
Pluchon8 小时前
硅基计划4.0 算法 字符串
java·数据结构·学习·算法
野生技术架构师8 小时前
1000 道 Java 架构师岗面试题
java·开发语言
青柠编程8 小时前
基于Spring Boot的选课管理系统架构设计
java·spring boot·后端
Mr.wangh9 小时前
Redis主从复制
java·数据库·redis
Porunarufu9 小时前
JAVA·顺序逻辑控制
java·开发语言
1710orange9 小时前
java设计模式:适配器模式
java·设计模式·适配器模式