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;
}
相关推荐
weixin_419658311 分钟前
Spring的三级缓存和SpringMVC的流程
java·spring·缓存
paopaokaka_luck11 分钟前
基于SpringBoot+Vue的DIY手工社预约管理系统(Echarts图形化、腾讯地图API)
java·vue.js·人工智能·spring boot·后端·echarts
自在极意功。12 分钟前
贪心算法深度解析:从理论到实战的完整指南
java·算法·ios·贪心算法
计算机学姐4 小时前
基于微信小程序的高校班务管理系统【2026最新】
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
一路向北⁢4 小时前
基于 Apache POI 5.2.5 构建高效 Excel 工具类:从零到生产级实践
java·apache·excel·apache poi·easy-excel·fast-excel
毕设源码-赖学姐7 小时前
【开题答辩全过程】以 基于Android的校园快递互助APP为例,包含答辩的问题和答案
java·eclipse
damo017 小时前
stripe 支付对接
java·stripe
麦麦鸡腿堡8 小时前
Java的单例设计模式-饿汉式
java·开发语言·设计模式
假客套8 小时前
Request method ‘POST‘ not supported,问题分析和解决
java
傻童:CPU8 小时前
C语言需要掌握的基础知识点之前缀和
java·c语言·算法