zoukankan      html  css  js  c++  java
  • linux php 环境word转pdf、excel转pdf、office转pdf

    最近项目中遇到一个需求,将word、excel文件转换成pdf,并且打上水印,我利用的是libreoffice,这个需要Java 的jdk环境.废话不多说,开撸

    1.在linux上搭建jdk环境

      文章链接 https://www.cnblogs.com/houss/p/11694260.html

    2.安装libreoffice所需的包(官网)

      我下载的镜像下载网址 

    mkdir /usr/libreoffice
    cd /usr/libreoffice
    wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm_sdk.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/6.3.2/rpm/x86_64/LibreOffice_6.3.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm.tar.gz tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm_sdk.tar.gz
    tar -zxvf LibreOffice_6.3.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

    cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm/RPMS
    yum install *.rpm
    cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS
    yum install *.rpm
    cd /usr/libreoffice/LibreOffice_6.3.2.2_Linux_x86-64_rpm_sdk/RPMS
    yum install *.rpm
    #测试是否安装成功:
    libreoffice6.3 -help

     

     出现上图证明安装成功

      报错 :

       

    报错

    /opt/libreoffice6.0/program/soffice.bin: error while loading shared libraries: libcairo.so.2: cannot open shared object file: No such file or directory

    执行命令:
    yum install cairo
    后再次执行命令:

    libreoffice6.3 -help

    再次报错

    /opt/libreoffice6.0/program/soffice.bin: error while loading shared libraries: libcups.so.2: cannot open shared object file: No such file or directory
    执行命令:

    yum install cups-libs
    后,再次执行命令:

    libreoffice6.3 -help

    报错:

    /opt/libreoffice6.0/program/soffice.bin: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory
    执行命令:

    yum install libSM

    转换的命令

    libreoffice6.3 --convert-to pdf:writer_pdf_Export 需转换的文件的地址 --outdir 输出地址

    例如 将当前文件夹下 家长如何帮助孩子.pptx 转换成pdf到当前文件夹下(word,excel也是如此,更多用法请自行研究)

      libreoffice6.3 --convert-to pdf:writer_pdf_Export ./家长如何帮助孩子.pptx --outdir ./

    PHP操作

      

    <?php
        exec("libreoffice6.3 --convert-to pdf:writer_pdf_Export ./家长如何帮助孩子.pptx --outdir ./",$log,$status);
        if($status == 0){
            echo '执行成功';
            printf($status);
        }

    关于word转pdf中文乱码问题处理

    (1):查看fonts目录:cat /etc/fonts/fonts.conf | grep fon
    得知字体存放位置:/usr/share/fonts

    (2): 把Windows下的字体C:WindowsFonts下的宋体,即simsun.ttc上传到linux服务器
    在fonts下新建Fonts文件 把字体上传到该路径下即可

    参考地址 https://www.cnblogs.com/chenpt/p/11096265.html

    3.pdf加水印,以及中文乱码问题处理

    https://www.cnblogs.com/houss/p/11697574.html 

  • 相关阅读:
    最大流问题的几种经典解法综述
    有上下界的网络流
    hiho一下
    poj 1018
    状压dp
    hdu 1043
    Poj1015
    7.14
    sgu 128
    (zhuan)
  • 原文地址:https://www.cnblogs.com/houss/p/11694136.html
Copyright © 2011-2022 走看看