先安装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,即可。