LibreOffice是OpenOffice办公套件衍生版, 同样免费开源,并且是跨平台的,支持windows和linux服务器安装。
$retval = 1;
// exec() might be disabled
$cmd = ‘D:/soft/LibreOfficePortablePrevious/LibreOfficeWriterPortable.exe --headless --convert-to pdf 1.doc --outdir ./‘;
if (function_exists(‘exec‘)){
@exec($cmd, $output, $retval);
}
// Did it work?
if ($retval > 0){
exit(‘process_failed‘);
}
echo ‘success‘;
直接使用yum安装即可:
yum install libreoffice
yum install libreoffice-headless //该工具用来启动Libreoffice
跟windows类似,执行以下命令即可转换文档:
soffice --headless --convert-to pdf {文档路径} --outdir {导出目录路径}
在linux下转换pdf,可能会出现中文字体不被识别,变成小方框的问题,解决步骤:
1.把Windows下的字体C:\Windows\Fonts下的常用字体,即simsun.ttc等复制到usr/share/fonts目录下。
2 修改字体权限
sudo chmod 644 simsun.ttc
3. 更新字体缓存:
sudo fc-cache -fv
【重启成功截图】
参考:http://www.884358.com/php-libreoffice-word-pdf/
原文:https://www.cnblogs.com/yangzailu/p/14308085.html