安装java环境
jdk文件
jdk-8u221-linux-x64.tar.gz
将压缩包移到指定目录
sudo mv jdk-8u221-linux-x64.tar.gz /usr/local/
#解压
cd /usr/local
sudo tar -zxvf /usr/local/jdk-8u221-linux-x64.tar.gz
配置java环境变量
sudo vim /etc/profile#在文件的最后添加如下内容
#Java Env
export JAVA_HOME=/usr/local/jdk1.8.0_221
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin#加载环境变量
source /etc/profile
测试java环境
sudo java -version#控制台打印
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
安装openoffice
文件
Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz
将压缩包移到指定目录(自定义)
sudo mv Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz /usr/local/#解压文件
cd /usr/local
sudo tar -zxvf /usr/local/Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz#这个时候会生成zh-CN文件
#重命名
sudo mv ./zh-CN/ ./openOffice
配置openoffice
cd openOffice/DEBS/
sudo dpkg -i *.deb
cd desktop-integration/
sudo dpkg -i openoffice4.1-debian-menus_4.1.6-9790_all.deb
#这个时候openoffice安装在/opt/openoffice4
安装jodConverter
文件
jodconverter-2.2.2.zip
#下载地址 :https://downloads.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-2.2.2.zip
安装配置
mv jodconverter-2.2.2.zip /opt
#解压
cd /opt
unzip /opt/jodconverter-2.2.2.zip
#进入目录
cd /opt/jodconverter-2.2.2/lib
加入中文字体,防止中文乱码
需要从windows中得字体文件中获取
#进入jdk字体目录
cd /usr/local/jdk1.8.0_221/jre/lib/fonts/
#建立fallback目录
mkdir fallback
# 将中文字体simhei.ttf、simsun.ttc放到fallback目录下
mv ~/simhei.ttf /usr/local/jdk1.8.0_221/jre/lib/fonts/fallback
mv ~/simsun.ttc /usr/local/jdk1.8.0_221/jre/lib/fonts/fallback
#将字体放到linux字体文件夹
cp /usr/local/jdk1.8.0_221/jre/lib/fonts/fallback/* /usr/share/fonts/#刷新字体缓存
fc-cache
启动openOffice
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
如果启动不起来,服务器版本ubuntu需要安装x-window的核心组件
apt-get install xserver-xorg
apt-get install x-window-system-core
测试
sudo java -jar /opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar ~/test.docx ~/test.pdf
关闭openoffice进程
ps -ef|grep soffice
kill -9 30415
php中使用
$command = "/usr/local/jdk1.8.0_221/bin/java -jar /opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/test.docx /tmp/test.pdf";
// $return_var返回值0或1,如果返回0则执行成功,返回1则执行失败
exec($command, $output, $return_var);
if ($return_var != 0) {echo "生成PDF失败";
}