zoukankan      html  css  js  c++  java
  • PHP使用LibreOffice实现word转pdf

    LibreOffice是OpenOffice办公套件衍生版, 同样免费开源,并且是跨平台的,支持windows和linux服务器安装。

    php调用命令实现文档转换:

    $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';

    Centos下的安装及使用

    直接使用yum安装即可:

    1. yum install libreoffice
    2. yum install libreoffice-headless  //该工具用来启动Libreoffice

    2、执行命令转换pdf文档

    跟windows类似,执行以下命令即可转换文档:

    soffice --headless --convert-to pdf {文档路径} --outdir {导出目录路径}

    3.解决中文不显示,变方框的问题

    在linux下转换pdf,可能会出现中文字体不被识别,变成小方框的问题,解决步骤:
    1.把Windows下的字体C:WindowsFonts下的常用字体,即simsun.ttc等复制到usr/share/fonts目录下。
    2 修改字体权限

    sudo chmod 644 simsun.ttc

    3. 更新字体缓存:

    sudo fc-cache -fv
    【杀死子进程命令】
    ps -ef|grep soffice | awk '{print $2}' | xargs kill -9
     
    【重启命令】
    /usr/lib64/libreoffice/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

     【重启成功截图】

    参考:http://www.884358.com/php-libreoffice-word-pdf/

  • 相关阅读:
    枚举类型(C#)
    如何在Delphi中安装组件
    操作系统知识点总结
    Java内部类学习笔记
    计算机网络笔试面试常考考点
    电话号码分身问题
    最长下降/上升子序列问题
    LeetCode(162):Find Peak Element
    LeetCode(153):Find Minimum in Rotated Sorted Array
    LeetCode(75):Sort Colors
  • 原文地址:https://www.cnblogs.com/yangzailu/p/14308085.html
Copyright © 2011-2022 走看看