liunx命令word文档和excel表格转换成pdf

1、 Anolis OS-8.x和centos7.x系统安装libreoffice

#直接使用yum安装

yum install -y libreoffice

#验证

libreoffice --version
LibreOffice 7.1.8.1 10(Build:1)

#后台启动libreoffice服务

nohup libreoffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &

#检查服务是否正常

ps -ef | grep libreoffice

root        4067    1015  0 10:06 pts/0    00:00:00 /usr/lib64/libreoffice/program/oosplash --headless --accept=socket,host=127.0.0.1,port=8100;urp; --nofirststartwizard
root        4096    4067  1 10:06 pts/0    00:00:00 /usr/lib64/libreoffice/program/soffice.bin --headless --accept=socket,host=127.0.0.1,port=8100;urp; --nofirststartwizard
root        4102    1015  0 10:06 pts/0    00:00:00 grep --color=auto libreoffice

#查看端口号

netstat -ntlup | grep 8100

tcp        0      0 127.0.0.1:8100          0.0.0.0:*               LISTEN      4096/soffice.bin

2、其他系统没有yum源直接下载rpm包进行安装

#下载地址:
https://zh-cn.libreoffice.org/download/libreoffice/
wget https://download.documentfoundation.org/libreoffice/stable/7.6.4/rpm/x86_64/LibreOffice_7.6.4_Linux_x86-64_rpm.tar.gz

#解压并安装

tar xf LibreOffice_7.6.4.1_Linux_x86-64_rpm.tar.gz
cd LibreOffice_7.6.4.1_Linux_x86-64_rpm/RPMS/
yum -y install *.rpm
#需要把版本号去掉,代码直接调用的libreoffice这个命令
mv  /usr/bin/libreoffice7.6 /usr/bin/libreoffice
#验证命令
libreoffice --version
#rpm包安装直接启动会报错,需要安装依赖
yum install libXinerama cairo -y
#后台启动服务
nohup libreoffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &

#检查服务是否正常
ps -ef | grep libreoffice

root        4067    1015  0 10:06 pts/0    00:00:00 /usr/lib64/libreoffice/program/oosplash --headless --accept=socket,host=127.0.0.1,port=8100;urp; --nofirststartwizard

root        4096    4067  1 10:06 pts/0    00:00:00 /usr/lib64/libreoffice/program/soffice.bin --headless --accept=socket,host=127.0.0.1,port=8100;urp; --nofirststartwizard

root        4102    1015  0 10:06 pts/0    00:00:00 grep --color=auto libreoffice

#查看端口号
netstat -ntlup | grep 8100

tcp        0      0 127.0.0.1:8100          0.0.0.0:*               LISTEN      4096/soffice.bin

3、将Windows字体拷贝到liunx服务器上防止乱码

将Windows字体(C:\Windows\Fonts)拷贝到

cd /usr/share/fonts
#安装依赖
yum install -y fontconfig mkfontscale
#执行两条命令
mkfontdir
fc-cache -fv

命令执行成功后终端最后一行会显示 fc-cache: succeeded

#验证
fc-list :lang=zh

手动将word文档转换成pdf文档

libreoffice --headless --invisible --convert-to pdf ./input.docx --outdir ./

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值