先安装libreoffice,然后使用命令
soffice --headless --invisible --convert-to pdf /tmp/abc.docx --outdir /tmp/
转换成PDF,几乎所有人都遇到
root@panda-dev:~/bin $ soffice --headless --convert-to txt:text blah.doc /usr/lib64/libreoffice/program/soffice.bin X11 error: Can't open display: Set DISPLAY environment variable, use -display option or check permissions of your X-Server (See "man X" resp. "man xhost" for details)
类似的问题,网上的帮助都是说要求启用:
/usr/bin/soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
然后 export DISPLAY=:0.0,就可以解决问题,但试了N次也完全不行。
其实只需要 yum install libreoffice-headless,即可。
LibreOffice头less模式转换文档

本文介绍如何正确安装并配置LibreOffice以在头less模式下将各种文档格式转换为PDF或TXT等格式。文章针对在命令行环境下无法正常显示的问题提供了具体的解决方案。
1798

被折叠的 条评论
为什么被折叠?



