最近由于遇到了要使用预览的功能,然后有一个doc转PDF的需求,然后需要使用libreoffice的功能,然后使用 soffice --headless --invisible --convert-to pdf /tmp/abc.docx --outdir /tmp/
就可以安装了。
libreoffice安装
[root@CentOS~]# yum install libreoffice
[root@CentOS~]# yum install libreoffice-headless
- 1
- 2
字体安装
[root@CentOS~]# mkdir /usr/share/fonts/simsun
##拷贝windows中的simsun.ttc到/usr/share/fonts/simsun/
然后执行以下命令
[root@CentOS~]#cd /usr/share/fonts/simsun
[root@CentOS~]#mkfontscale
[root@CentOS~]#mkfontdir
[root@CentOS~]#fc-cache -fv
执行以下命令让字体生效
[root@CentOS~]#source /etc/profile
soffice --headless --invisible --convert-to pdf /tmp/abc.docx --outdir /tmp/
######python调用
借助libreoffice将doc进行格式转换
#!/usr/bin/env python
# coding:utf-8
import subprocess
output = subprocess.check_output(["soffice","--headless","--invisible","--convert-to","docx","/home/requiem/workspace/python3/test.doc","--outdir","/home/requiem/workspace/python3/"])########################
转自:https://blog.csdn.net/u011053407/article/details/74989837
https://blog.csdn.net/qq_30371793/article/details/76578181