linux php 环境word转pdf、excel转pdf、office转pdf

最近项目中遇到一个需求,将word、excel文件转换成pdf,并且打上水印,我利用的是libreoffice,这个需要Java 的jdk环境.废话不多说,开撸

1.在linux上搭建jdk环境

  文章链接 https://www.cnblogs.com/houss/p/11694260.html

2.安装libreoffice所需的包(官网)

  我下载的镜像下载网址 

mkdir /usr/libreoffice
cd /usr/libreoffice
wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm_sdk.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gz tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm_sdk.tar.gz
cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm/RPMS
yum install *.rpm
cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS
yum install *.rpm
cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm_sdk/RPMS
yum install *.rpm
#测试是否安装成功:
libreoffice6.3 -help

 

 出现上图证明安装成功

转换的命令

libreoffice6.3 --convert-to pdf:writer_pdf_Export 需转换的文件的地址 --outdir 输出地址

例如 将当前文件夹下 家长如何帮助孩子.pptx 转换成pdf到当前文件夹下(word,excel也是如此,更多用法请自行研究)

  libreoffice6.3 --convert-to pdf:writer_pdf_Export ./家长如何帮助孩子.pptx --outdir ./

关于word转pdf中文乱码问题处理

(1):查看fonts目录:cat /etc/fonts/fonts.conf | grep fon
得知字体存放位置:/usr/share/fonts

(2): 把Windows下的字体C:\Windows\Fonts下的宋体,即simsun.ttc上传到linux服务器
在fonts下新建Fonts文件 把字体上传到该路径下即可

参考地址 https://www.cnblogs.com/chenpt/p/11096265.html

3.pdf加水印,以及中文乱码问题处理

https://www.cnblogs.com/houss/p/11697574.html 

猜你喜欢

转载自www.cnblogs.com/houss/p/11694136.html