Linux下office(doc,docx,xls,xlsx,ppt,pptx)转pdf

安装office套件

yum install libreoffice

转换脚本

soffice --headless --invisible --convert-to pdf 源文件路径.doc --outdir 生成文件保存目录

SHELL脚本

#!/bin/sh    

source=$1  
echo ${source}   
soffice --headless --invisible --convert-to pdf ${source} --outdir /tmp/ 

常见错误

/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)

只需要 yum install libreoffice-headless,即可。

发表评论

邮箱地址不会被公开。 必填项已用*标注