php CentOS7下通过OpenOffice+jodconverter实现将Excel转PDF

一、安装openoffice

1.下载openoffice

openoffice官网 http://www.openoffice.org/download/index.html

wget -c 资源地址  #使用 wget -c 断点续传
2.解压openoffice
3.安装
CD zh-CN/RPMS/
yum localinstall *.rpm
4.再安装(我觉得不装这个也行,未测试)
CD desktop-integration/
yum localinstall openoffice4.1.7-redhat-menus-4.1.7-9800.noarch.rpm
5.启动
nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
6.查看是否成功
netstat -lnp | grep 8100

显示:
tcp 0 0 127.0.0.1:8100 0.0.0.0:* LISTEN 8987/soffice.bin
成功!

二、安装java运行环境

查看yum库中都有哪些jdk版本,运行:

yum search java|grep jdk

选择版本进行安装:

yum install java-11-openjdk.x86_64

查看是否安装成功:

java -version

显示:

openjdk version "11.0.5" 2019-10-15 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)

三、下载JODConverter(Java OpenDocument Converter)

JODConverter下载地址:https://sourceforge.net/projects/jodconverter

四、测试转换

test.xls=>test.pdf

cd jodconverter-2.2.2/lib
java -jar jodconverter-cli-2.2.2.jar test.xls test.pdf

五、解决中文不显示问题

1.下载字体

simhei.ttf 黑体
simsun.ttc 宋体
两种字体文件
放到如下目录
/opt/openoffice4/share/fonts/truetype

2.更新字体缓存
fc-cache
3.重启openoffice
ps ax|grep soffice 

显示如下:

22739 pts/5 S 0:00 /bin/sh /opt/openoffice.org3/program/soffice -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard 
22747 pts/5 Sl 0:01 /opt/openoffice.org3/program/soffice.bin -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard 
23789 pts/5 S+ 0:00 grep soffice 

关闭soffice进程

kill 22739 

再次启动openoffice

nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

六、php调用

<?php
$command = "java -jar jodconverter-cli-2.2.2.jar test.xls test.pdf";
//exec($command, $output);
//system($command);
passthru($command);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值