aspose-words中插入附件及遇到的问题

aspose-words版本:21.1

java:1.8

目标:

前端使用tinymce编辑一段内容,后端使用aspose-words将html转为word,并将html中的附件转换为word中的附件。

形如:

实现方案:

使用正则表达式找出需要替换的附件位置,然后再使用aspose-words替换为附件。

关键代码:

java 复制代码
    public void insertOleObjectAsIcon() throws Exception
    {
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
		// windows开发环境使用绝对路径,生产环境可以使用文件流进行传输
        builder.insertOleObjectAsIcon("D:/source.docx", "Word.Document.12",false,"D:/word.ico" ,"attachmentFile.docx");
        doc.save("D:/output.docx");
    }

遇到的问题:

  1. 使用insertOleObject方法会导致只显示图片icon,不显示文件名称。prepsentation参数不能为null,会报空指针.
  2. java.io.EOFException : End of file reached,源码被加扰,无法明确具体原因,替换为ico后缀的图片文件后,错误消失。
  3. java.lang.UnsupportedOperationException : Not implemented format is met. 源码被加扰,无法明确具体原因,猜测文件过大(6K)。具体阈值未知。
  4. java.lang.ArrayIndexOutBoundsException: 456 文件过小(1K)。具体阈值未知。

使用2.3K大小的ico,操作成功并正常显示。

参考:

相关推荐
小刘在重生~16 分钟前
Java 集合|Collection、List、ArrayList、LinkedList、泛型、Collections 工具类
java·数据结构·list
我不会起名字32232 分钟前
一天一道算法题(29):单调栈
java·数据结构·python·算法·leetcode·golang·单调栈
XR12345678839 分钟前
医院移动医护零漫游无线网络选型指南
java·后端·struts
干到60岁退休的码农1 小时前
13.构建登录接口响应数据
java·spring boot·mybatis
水巷石子1 小时前
学习langChain4j的第二天,体验springBoot中的starter
java·spring boot·学习·spring·langchain4j
ly76891 小时前
Spring Bean生命周期全流程:从BeanDefinition到销毁
java·后端·spring·bean生命周期·beandefinition·初始化回调
君顾11 小时前
智慧场馆解决方案小程序系统实战:从架构设计到上线指南
java·开发语言·智慧场馆
zhougl9961 小时前
Dockerfile实战教程
java·开发语言·spring boot
新时代牛马1 小时前
Linux 驱动调试完整篇:从printk/dev_dbg、动态调试到 debugfs/ftrace 排障
java·linux·服务器