使用OpenOffice将office文件转为pdf

0.参考博客:https://blog.csdn.net/weixin_39468112/article/details/89203815
1.首先安装openOffice4.1
2.添加依赖

<dependency>
	<groupId>org.jodconverter</groupId>
	<artifactId>jodconverter-core</artifactId>
	<version>4.2.2</version>
</dependency>
<dependency>
	<groupId>org.jodconverter</groupId>
	<artifactId>jodconverter-local</artifactId>
	<version>4.2.2</version>
</dependency>
<dependency>
	<groupId>org.jodconverter</groupId>
	<artifactId>jodconverter-spring-boot-starter</artifactId>
	<version>4.2.2</version>
</dependency>

3.yaml配置软件安装路径(如果在生产环境需提前安装好OpenOffice)

#office转pdf,office-home如果项目部署在linux上记得修改
jodconverter:
  local:
    enabled: true
    #centos7要先安装openOffice
    office-home: C:\Program Files (x86)\OpenOffice 4
    max-tasks-per-process: 10
    port-numbers: 8100

4.使用:

@Autowired
DocumentConverter converter;
converter.convert(sourceFile).to(pdfFile).execute();

5.报错解决:一般是项目目录有中文的原因

posted @ 2021-10-29 15:25  LHX2018  阅读(464)  评论(0编辑  收藏  举报