• 周五. 8月 19th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

python使用libreoffice将word转换为pdf

admin

11月 28, 2021
环境 CentOS7.2 | Python3.8.1 | LibreOffice6.4.7
 
一、python安装
 
#安装依赖
yum -y install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum -y install zlib* yum -y install python-setuptools
#安装python
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz tar -zxvf Python-3.8.1.tgz cd Python-3.8.1.tgz ./configure –prefix=/usr/local/python3 make && make install
#建立软连
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 ln -s /usr/local/python3/bin/python3 /usr/bin/python3
#升级pip3
pip3 install –upgrade pip
#缺少ssl的情况
yum install openssl yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
#如有低版本的python3,执行如下命令
rpm -qa|grep python3|xargs rpm -ev –allmatches –nodeps   //卸载pyhton3
whereis python3 |xargs rm -frv   //删除所有残余文件
#成功卸载!
whereis python   //查看现有安装的python
 
二、LibreOffice安装
 
#卸载已有的libreoffice
yum erase libreoffice*
#下载所需要的的安装包
#解压
tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm_langpack_zh-CN.tar.gz tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm_sdk.tar.gz tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm.tar.gz
#安装rpm
#分别到对应解压目录里面的RPMS目录下,执行如下语句(有3个目录)
yum -y install *.rpm
#查看libreoffice安装情况
which libreoffice6.4 # 看到路径:/usr/bin/libreoffice6.4 ll /usr/bin/libreoffice6.4 # 得到路径:/opt/libreoffice6.4/program/soffice,说明安装成功:/opt/libreoffice6.4 #增加软连接 ln -s /opt/libreoffice6.4/program/soffice /usr/bin/soffice
#启动
/opt/libreoffice6.4/program/soffice –headless –accept=”socket,host=127.0.0.1,port=8100;urp;” –nofirststartwizard &
 
EXMAPLE:
 
import os
 
import_file_name = "/test/seo.docx"
output_file_path = "/test/"
os.system("libreoffice6.4 --headless --convert-to pdf %s --outdir %s" % (import_file_name, output_file_path))

发表回复

您的电子邮箱地址不会被公开。