安装LibreOffice
使用yum命令安装:
sudo yum install libreoffice
命令行转换(核心技巧)
libreoffice --headless --convert-to pdf:writer_pdf_Export input.docx --outdir /output/path--headless表示无界面运行,--convert-to指定格式及过滤器)find . -name "*.docx" | while read file; do libreoffice --headless --convert-to pdf "$file"; done解决中文乱码
/usr/share/fonts),更新字体缓存:sudo fc-cache -fv性能优化
--norestore(禁止恢复会话)和--nofirststartwizard(跳过启动向导)提升速度。使用unoconv工具
sudo yum install unoconvunoconv -f pdf input.docx(需先启动LibreOffice服务)集成到编程环境
Runtime.getRuntime().exec()执行上述命令行指令。subprocess模块实现自动化转换。sudo提升权限。soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"。参考来源: