本文只实现了doc文档转换至Pdf文档,力求简单粗暴,so代码有很多需改进地方,故只做记录,方便日后查询
关于pdf转swf需要另外下载SWFTools软件,这个功能后续有时间再更新
使用到的技术pdf.js + jodconverter + libreoffice(openOffice衍生版)
- 导入java包
<!-- jodconverter 文件转换 2.2.2版本已可转换-->
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- 新版本,有空可测试 -->
<!-- https://mvnrepository.com/artifact/org.jodconverter/jodconverter-core -->
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-core</artifactId>
<version>4.1.0</version>
</dependency>
- 安装libreoffice软件
下载地址:https://zh-cn.libreoffice.org/
安装成功后,可使用命令启动服务
命令:
cd C:\Program Files\LibreOffice\program //进入我的安装目录
soffice.exe -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard & //启动服务
netstat -ano|findstr "8100" //查看端口8100的监听情况,就是看有没启动
当然也可使用任务管理器查看服务开启状态(另一个是不是bin不太记得了,如有错误烦请指出):
三、编写文件转换工具类(没有SWFTools软件不要转换swf格式)
import com.artofsolving.jodconverter.DocumentConverter;