因业务需求需要,用unoconv就可以轻松地实现利用LibOffice可以打开的文档的转换。

服务器版本

环境系统版本
LinuxRed Hat Enterprise Linux Server release 7.6 (Maipo)
LinuxCentOS Linux release 7.6

需要准备软件包

软件及版本下载链接
LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gzhttps://www.libreoffice.org/donate/dl/rpm-x86_64/6.3.4/zh-CN/LibreOffice_6.3.4_Linux_x86-64_rpm.tar.gz
unoconv-master.ziphttps://github.com/unoconv/unoconv/archive/master.zip

在这里插入图片描述

一、安装libreoffice

① 下载libreoffice

http://www.libreoffice.org/download/
点击 download 后稍等一会 会自动下载

wget https://www.libreoffice.org/donate/dl/rpm-x86_64/6.3.4/zh-CN/LibreOffice_6.3.4_Linux_x86-64_rpm.tar.gz

在这里插入图片描述

② 解压
tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gz
③ 进入到解压后RPM目录
cd LibreOffice_6.3.2.2_Linux_x86-64_rpm/RPMS
④ 安装所有rpm包
yum install *.rpm
⑤ 启动 libreoffice
/opt/libreoffice6.3/program/soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &

二、安装 unovocn

①下载

git地址 :https://github.com/dagwieers/unoconv
依然使用 wget 下载

wget https://github.com/dagwieers/unoconv/archive/master.zip
②解压
unzip unoconv-master.zip
③安装unovocn
make install
④ 测试

进入解压后的 unoconv-master 目录 运行 unoconv -f pdf CHANGELOG.md 来测试。

⑤ 异常报错

/usr/lib64/libreoffice/program/soffice.bin X11 error: Can’t open display:
Set DISPLAY environment variable, use -display option
or check permissions of your X-Server
(See “man X” resp. “man xhost” for details)

⑥ 解决方案

网上查了一下 需要安装一些别的软件就可以 yum install libreoffice-headless 用这个命令安装好这些依赖即可

再运行 unoconv -f pdf CHANGELOG.md 即可看到同目录已经生成了 相应的pdf文件

四、生成PDF乱码问题

① 准备字体

将Windows下的Fonts,如:C:\Windows\Fonts,压缩成Fonts.zip压缩包
在这里插入图片描述

② linux操作

将压缩包拷贝到Linux目录下,执行如下命令即可:

unzip Fonts.zip
mkdir /usr/share/fonts/win
cp Fonts/* /usr/share/fonts/win
cd /usr/share/fonts/win
chmod  -Rf 755 *
mkfontscale  
mkfontdir  
fc-cache –fv 

重启服务器即可。

reboot

再次测试,一切正常!!!

下一篇:(企业内部)SpringBoot 在线预览 doc,doxc,xls,xlsx,ppt,pptx 文件
https://gblfy.blog.csdn.net/article/details/102847228

yum安装Unoconv
unoconv 在线预览 doc,doxc,xls,xlsx,ppt,pptx 文件功能环境搭建
https://gblfy.blog.csdn.net/article/details/102847276

Logo

更多推荐