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;
}
相关推荐
不懂的浪漫2 分钟前
mqtt-plus 架构解析(四):MqttMessageInterceptor 的扩展点设计
java·spring boot·物联网·mqtt
西海天际蔚蓝4 分钟前
AI配合写的第一个demo系统页面
java·人工智能
小旭952718 分钟前
Spring Security 实现权限控制(认证 + 授权全流程)
java·后端·spring
金銀銅鐵24 分钟前
[Java] 如何通过 cglib 的 FastClass 调用一个类中的“任意”方法?
java·后端
阿维的博客日记42 分钟前
为什么会增加TreeMap和TreeSet这两类,有什么核心优势吗?可以解决什么核心痛点?
java·treeset·treemap
dllxhcjla1 小时前
黑马头条1
java
宠友信息1 小时前
一套基于uniapp+springboot完整社区系统是如何实现的?友猫社区源码级功能解析
java·spring boot·后端·微服务·微信·uni-app
humors2211 小时前
各厂商工具包网址
java·数据库·python·华为·sdk·苹果·工具包
无限进步_1 小时前
【C++&string】大数相乘算法详解:从字符串加法到乘法实现
java·开发语言·c++·git·算法·github·visual studio
海兰2 小时前
使用 Spring AI 打造企业级 RAG 知识库第二部分:AI 实战
java·人工智能·spring