简体   繁体   English

无法通过PHP exec执行DOC到PDF的转换命令

[英]Unable to execute DOC to PDF conversion command via PHP exec

I am unable to execute the following command under user apache using php exec function. 我无法使用php exec函数在用户apache下执行以下命令。

exec('/usr/bin/libreoffice --headless --convert-to pdf --outdir /var/www/html/ /var/www/html/coverpage.doc');

OS : CentOS 6.4 Final 操作系统:CentOS 6.4 Final

Any help or suggestions are highly appreciable. 任何帮助或建议都是非常可取的。 Thanks 谢谢

First check for the permission given for /var/www folder. 首先检查/ var / www文件夹的权限。 Give apache:apache as owner for /var/www/ . apache:apache作为/var/www/所有者。

Use the below command to install libreoffice headless package if it is not installed. 如果未安装libreoffice headless软件包,请使用以下命令安装。

sudo yum install openoffice.org-headless

This has worked for me in centOS. 这在centOS中对我有用。

There may be numerous reasons start by redirecting command error output to a file and then continue troubleshooting from there : 可能有很多原因,首先将命令错误输出重定向到文件,然后从那里继续进行故障排除:

exec('/usr/bin/libreoffice --headless --convert-to pdf --outdir /var/www/html/ /var/www/html/coverpage.doc 2> /tmp/error.txt'); exec('/ usr / bin / libreoffice --headless --convert-to pdf --outdir / var / www / html / /var/www/html/coverpage.doc 2> /tmp/error.txt');

After running the script check /tmp/error.txt. 运行脚本后,检查/tmp/error.txt。

  1. I would first of all try it with giving absolute paths to the command. 首先,我将尝试给出命令的绝对路径。

  2. I suspect that the libreoffice binary does not work -- you have to locate the soffice binary and see if that works. 我怀疑libreoffice二进制文件不起作用-您必须找到该soffice二进制文件并查看是否可行。

  3. Then, your --convert-to pdf is not sufficient. 然后,您的--convert-to pdf是不够的。 It needs to be: 它必须是:

    --convert-to pdf:writer_pdf_Export -转换为pdf:writer_pdf_Export

  4. Next, the command will not work if there is already a LibreOffice GUI instance up and running on your system. 接下来,如果您的系统上已经存在并在运行LibreOffice GUI实例,则该命令将不起作用。 Add this additional parameter to your command: 将此附加参数添加到您的命令中:

    "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" “-env:UserInstallation =文件:/// tmp目录/ LibreOffice_Conversion_ $ {USER}”

  5. Also, make sure that the --outdir /pdf you specify does exist, and that you have write permission to it. 另外,请确保您指定的--outdir / pdf确实存在,并且您对其具有写权限。 Or, rather use a different output dir. 或者,而是使用其他输出目录。 Even if it is just for the first testing and this debugging round: 即使仅用于第一次测试和此轮调试:

    $ mkdir ${HOME}/lo_pdfs $ mkdir $ {HOME} / lo_pdfs

  6. This works for me on Mac OS X Mavericks 10.9.5 with LibreOffice v4.4.3.2 (using my specific path for the binary soffice which will be different for you anyway...). 这对我在Mac OS X Mavericks 10.9.5和LibreOffice v4.4.3.2上有效(使用我的二进制文件专用路径,无论如何您都将有所不同...)。

     /path/to/soffice 

    --headless

    "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"

    --convert-to pdf:writer_pdf_Export

    --outdir ${HOME}/lo_pdfs path/to/test.docx

If this will not work try this answer Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working 如果这不起作用,请尝试以下答案命令`libreoffice --headless --convert-to pdf test.docx --outdir / pdf`不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM