需求:
将DOC/DOCX/XLS/XLSX/PPT/PPTX/TXT/JPG/PNG 转成PDF
方案:
使用JodConvert4.2.*版本 + OpenOffice
具体步骤
1.Centos 安装OpenOffice
(1) 下载地址:https://www.openoffice.org/download/index.html
(2)解压缩 tar -xzvf Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_en-US.tar.gz
(3) 进入en-US/RPMS
[root@localhost tools]# cd en-US/
[root@localhost en-US]# cd RPMS/
[root@localhost RPMS]#
[root@localhost RPMS]# rpm -ivh *.rpm
准备中... ################################# [100%]
正在升级/安装...
1:openoffice-ure-4.1.6-9790 ################################# [ 2%]
2:openoffice-core01-4.1.6-9790 ################################# [ 5%]
3:openoffice-en-US-4.1.6-9790 ################################# [ 7%]
4:openoffice-impress-4.1.6-9790 ################################# [ 10%]
5:openoffice-en-US-base-4.1.6-9790 ################################# [ 12%]
6:openoffice-en-US-calc-4.1.6-9790 ################################# [ 15%]
7:openoffice-en-US-draw-4.1.6-9790 ################################# [ 17%]
8:openoffice-en-US-help-4.1.6-9790 ################################# [ 20%]
9:openoffice-en-US-impress-4.1.6-97################################# [ 22%]
10:openoffice-en-US-math-4.1.6-9790 ################################# [ 24%]
11:openoffice-en-US-res-4.1.6-9790 ################################# [ 27%]
12:openoffice-en-US-writer-4.1.6-979################################# [ 29%]
13:openoffice-base-4.1.6-9790 ################################# [ 32%]
14:openoffice-calc-4.1.6-9790 ################################# [ 34%]
15:openoffice-core02-4.1.6-9790 ################################# [ 37%]
16:openoffice-core03-4.1.6-9790 ################################# [ 39%]
17:openoffice-core04-4.1.6-9790 ################################# [ 41%]
18:openoffice-core05-4.1.6-9790 ################################# [ 44%]
19:openoffice-core06-4.1.6-9790 ################################# [ 46%]
20:openoffice-core07-4.1.6-9790 ################################# [ 49%]
21:openoffice-draw-4.1.6-9790 ################################# [ 51%]
22:openoffice-images-4.1.6-9790 ################################# [ 54%]
23:openoffice-4.1.6-9790 ################################# [ 56%]
24:openoffice-math-4.1.6-9790 ################################# [ 59%]
25:openoffice-writer-4.1.6-9790 ################################# [ 61%]
26:openoffice-brand-writer-4.1.6-979################################# [ 63%]
27:openoffice-brand-math-4.1.6-9790 ################################# [ 66%]
28:openoffice-brand-base-4.1.6-9790 ################################# [ 68%]
29:openoffice-brand-calc-4.1.6-9790 ################################# [ 71%]
30:openoffice-brand-draw-4.1.6-9790 ################################# [ 73%]
31:openoffice-brand-en-US-4.1.6-9790################################# [ 76%]
32:openoffice-brand-impress-4.1.6-97################################# [ 78%]
33:openoffice-ogltrans-4.1.6-9790 ################################# [ 80%]
34:openoffice-gnome-integration-4.1.################################# [ 83%]
35:openoffice-graphicfilter-4.1.6-97################################# [ 85%]
36:openoffice-javafilter-4.1.6-9790 ################################# [ 88%]
37:openoffice-onlineupdate-4.1.6-979################################# [ 90%]
38:openoffice-ooofonts-4.1.6-9790 ################################# [ 93%]
39:openoffice-ooolinguistic-4.1.6-97################################# [ 95%]
40:openoffice-pyuno-4.1.6-9790 ################################# [ 98%]
41:openoffice-xsltfilter-4.1.6-9790 ################################# [100%]
[root@localhost RPMS]#
(4) 启动服务
[root@localhost program]# nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
[root@localhost data]# lsof -i:8100
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
soffice.b 256709 root 19u IPv4 47394158 0t0 TCP localhost:xprint-server (LISTEN)
2.配置pom.xml
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.2.2</version>
</dependency>
3.Demo
// String openOfficePath = "C:/Program Files (x86)/OpenOffice 4";//windows路径
String openOfficePath = "/opt/openoffice4";//linux路径
LocalOfficeManager officeManager = LocalOfficeManager.builder().officeHome(openOfficePath).install().build();
officeManager.start();
JodConverter.convert(new File("/program/data/123.txt")).to(new File("/program/data/123.pdf")).execute();