最近项目中遇到一个需求,将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 ./

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

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

01-23 09:06
查看更多