可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Running headless Ubuntu server 12.something.
root@server: chown www-data /my/path/ -R
root@server: chgrp www-data /my/path/ -R
root@server: chmod 755 /my/path/ -R
root@server: libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf
Works like a charm.
root@server: sudo -i -u www-data
$libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf Error: Please reverify input parameters...
Damn.
root@server: sudo -i -u someotheruser
$libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf Error: Please reverify input parameters...
Damn.
Anyone have any idea? Trying to research this just confused me more. Is this probably a bug or some dependency quirk?
回答1:
I finally found an answer to this... Add:
export HOME=/tmp &&
to the beginning, so:
export HOME=/tmp && libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
That worked for me on CentOS 6.5, and as shell_exec() in PHP.
回答2:
We faced the same issue when running the soffice
binary headless (LibreOffice 5.0.5.2) in a CloudFoundry (Diego) container as part of a NodeJS app.
It seems newer versions of libreoffice
do not expect a writeable HOME
, but try to write to TMPDIR
.
strace
showed: 8349 mkdir("app/tmp", 0777) = -1 ENOENT (No such file or directory) 8349 open("app/tmp/lu8349pzgegi.tmp", O_RDWR|O_CREAT|O_EXCL, 0600) = -1 ENOENT (No such file or directory)
with TMPDIR=app/tmp
We fixed it by setting TMPDIR
to a directory that is writeable by the App process' user, i.e. TMPDIR=/tmp
on CloudFoundry:
process.env.TMPDIR = "/tmp";
回答3:
I had this same error, but the problem wasn't root access. The command was wrong.
This worked for me, getting text from a doc in LibreOffice 4.2.:
soffice --headless --convert-to txt:Text file_to_convert.odt
(http://ask.libreoffice.org/en/question/14130/how-do-i-install-filters-for-the-soffice-command/)
回答4:
Much as Jacek stated in his comment, make the user you are trying to execute the command as a sudoer with no password required. Then change your libreoffice command to be
sudo libreoffice
Worked for me. I had the same issue.
回答5:
You can not run libreoffice soffice binary with www-data user. Use a user with sudo privilege instead. Check my Gist https://gist.github.com/nathanielvarona/423bda9e4a8a4f0f9bbf#file-soffice-listener-sh
And since you are going to use this in PHP. Just give a try also to PHP-FPM. Install it and then modify the /etc/php5/fpm/pool.d/www.conf file.
From
user = www-data group = www-data
To:
user = ubuntu group = ubuntu
I've successfully run this in AWS EC2 and also with my VBox VMs.
回答6:
I would take a look on
http://dag.wieers.com/home-made/unoconv/
This tool should be more suited to convert your files properly. It is available on the ubuntu repos, so there should be no problem with installation.