CentOS 生成 PDF 文档

发布于 2023-02-02 12:31:43 字数 3261 浏览 123 评论 0

libreoffice

安装,镜像地址: http://mirrors.ustc.edu.cn/tdf/libreoffice/stable

wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.3.5/rpm/x86_64/LibreOffice_6.3.5_Linux_x86-64_rpm.tar.gz
wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.3.5/rpm/x86_64/LibreOffice_6.3.5_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.3.5/rpm/x86_64/LibreOffice_6.3.5_Linux_x86-64_rpm_sdk.tar.gz

tar -xzvf LibreOffice_6.3.5_Linux_x86-64_rpm.tar.gz
tar -xzvf LibreOffice_6.3.5_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
tar -zxvf LibreOffice_6.3.5_Linux_x86-64_rpm_sdk.tar.gz

yum install LibreOffice_6.3.5.2_Linux_x86-64_rpm/RPMS/*.rpm
yum install LibreOffice_6.3.5.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm        
yum install LibreOffice_6.3.5.2_Linux_x86-64_rpm_sdk/RPMS/*.rpm

启动,自启动设置

# 启动命令
libreoffice6.3 --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard

soffice -accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager

#修改启动脚本
vim /etc/rc.d/rc.local
#末尾添加
libreoffice6.3 --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard
#脚本授权
chmod +x /etc/rc.d/rc.local

检查

ps -ef|grep libreoffice

转换,成功后生成同名 pdf

libreoffice6.3 --headless --invisible --convert-to pdf xxx.docx
libreoffice6.3 --headless --invisible --convert-to pdf <待转换的word路径> --outdir <生成的pdf文件名>

出错情况

样例1

/opt/libreoffice6.3/program/soffice.bin: error while loading shared libraries: libcairo.so.2: cannot open shared object file: No such file or directory

解决

yum install cairo

看是否可以,不行继续

yum install cups-libs

看是否可以,不行继续

yum install libSM

centos中转换中文乱码

查看操作系统是否中文字体

yum -y install cups-libs fontconfig

fc-list

添加中文字体

mkdir /usr/share/fonts/chinese
chmod -R 755 /usr/share/fonts/chinese

中文字体文件在 windows 系统中 c 盘下的 Windows/Fonts(C:\Windows\Fonts),把相关的字体放入到 chinese 目录中

配置字体

vim /etc/fonts/fonts.conf

<!-- Font directory list -->

        <dir>/usr/share/fonts</dir>
        <dir>/usr/share/X11/fonts/Type1</dir>
        <dir>/usr/share/X11/fonts/TTF</dir>
        <dir>/usr/local/share/fonts</dir>
        <dir>/usr/local/share/fonts/chinese</dir>

<!--

刷新字体缓存

fc-cache
fc-list

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

七月上

暂无简介

文章
评论
28 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文