linux利用LibreOffice & unoconv 实现word转pdf
libreoffice官网:http://www.libreoffice.org/
wget下载LINUX对应32/64位rpm包
32位 http://ftp.kaist.ac.kr/tdf/libreoffice/stable/5.4.0/rpm/x86/LibreOffice_5.4.0_Linux_x86_rpm.tar.gz
64位 http://ftp.kaist.ac.kr/tdf/libreoffice/stable/5.4.0/rpm/x86_64/LibreOffice_5.4.0_Linux_x86-64_rpm.tar.gz
arm下载:https://www.oracle.com/database/technologies/instant-client/linux-arm-aarch64-downloads.html
tar -zxvf LibreOffice_5.4.0_Linux_x86-64_rpm.tar.gz
cd RPMS/
rpm -ivh *.rpm
cd /opt/libreoffice5.4/program
nohup soffice --headless --accept="socket,host=127.0.0.1,port=8001;urp;" --nofirststartwizard &
unoconv
http://dag.wiee.rs/home-made/unoconv/unoconv-0.7.tar.gz
vi /etc/profile
将soffice写入PATHexport PATH=$PATH:/usr/local/unoconv-0.7
source /etc/profile
unoconv --listener &
PHP代码中转换:
exec('soffice --headless --invisible --convert-to pdf ./test.docx --outdir ./'); //linux&windows
exec('unoconv -f pdf ./test.docx'); //linux
注:windows需将libreoffice/soffice加入path,配置php.ini关掉安全模式safe_mode = off,disable_functions = proc_open, popen, exec, system, shell_exec ,把exec去掉。)
exec("soffice --headless --invisible --convert-to pdf $path 2>&1", $output);
foreach ($output as &$o){
$o = iconv('GBK', 'UTF-8', $o);
}
print_r($output);
php exec 为啥执行不了?
exec("unoconv -f pdf xx.docx 2>&1", $output);
print_r($output);
查看出错原因,如是否将unoconv链接到bin目录
/opt/libreoffice5.4/program/soffice --headless --accept="socket,host=127.0.0.1,port=8001;urp;" --nofirststartwizard &
一般在安装openoffice/libreoffice中会遇到一个权限分配的问题。
打开系统“组件服务”-》计算机-》我的电脑-》DCOM配置-》OpenOfficeService Manager (Ver 1.0),鼠标右键打开,更改安全设置,在“安全”里将所有权限都更改为“自定义”,这里包括“启动和激活权限”、“访问权限”、“配置权限”都更改为“自定义”,这里虽然看起来“配置权限”似乎不需要改。然后点击“编辑”-》“添加”-》“高级”-》“立即查找”,找到Everyone成员,添加后,赋予其全部权限。这样将“启动和激活权限”、“访问权限”、“配置权限”都添加了Everyone用户后,再点击“标识”,选择交互式用户,重启下电脑即可解决问题。
在Windows Server 2008或Windows7下将openoffice注册到服务里