在 CentOS 下用 LibreOffice 将文档(如 docx、xlsx、pptx 等)转换为 PDF,常见做法如下:
yum install libreoffice libreoffice-headless
dnf install libreoffice-core libreoffice-writer libreoffice-calc libreoffice-impress
建议同时安装
libreoffice-headless(无界面运行支持)
libreoffice --headless --convert-to pdf 文件.docx
libreoffice --headless --convert-to pdf --outdir /tmp/output 文件.docx
libreoffice --headless --convert-to pdf *.docx
可能是 用户目录冲突(尤其是 root 用户):
libreoffice --headless --convert-to pdf -env:UserInstallation=file:///tmp/lo_profile 文件.docx
或创建专用用户运行。
安装中文字体:
yum install wqy-zenhei-fonts
# 或
yum install google-noto-cjk-fonts
然后刷新字体缓存:
fc-cache -fv
尝试:
soffice --headless --convert-to pdf 文件.docx
在 Java / Python / Shell 中调用时:
UserInstallation 目录timeout 防止卡死timeout 60 libreoffice --headless --convert-to pdf file.docx
如需高并发:
libreoffice + supervisorjodconverter + LibreOfficeonlyoffice / unoconv如果你能说明:
我可以给你更精确的方案。