UNOCONV failing to convert files in PHP on CentOS

634 views Asked by At

I have UNOCONV library installed on my CentOS 7.3.16.11. When I run file conversion from CLI it works fine, and I'm getting PDF document back:
unoconv -d spreadsheet --format=pdf -o temp/ ./document.docx

But when I try to execute it from PHP 5.6.29, it doesn't give me any output PDF. I'm getting an error from Python environment:
Traceback (most recent call last): File "/usr/bin/unoconv", line 1196, in <module> run() File "/usr/bin/unoconv", line 1108, in run office_environ(of) File "/usr/bin/unoconv", line 202, in office_environ os.environ['PATH'] = realpath(office.basepath, 'program') + os.pathsep + os.environ['PATH'] File "/usr/lib64/python2.7/UserDict.py", line 23, in \__getitem__ raise KeyError(key) KeyError: 'PATH'

Checked the paths in my environment with:
echo $PATH
The output is:
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/username/.local/bin:/home/username/bin

What can be wrong with running UNOCONV from php?

1

There are 1 answers

1
karlsebal On

Beside figuring out how to set PATH properly while using php you may hack the unoconv script and change line 1174 from

os.environ['PATH'] = realpath(office.basepath, 'program') + os.pathsep + os.environ['PATH']

to

os.environ['PATH'] = realpath(office.basepath, 'program') + os.pathsep + os.environ['PATH'] if 'PATH' in os.environ.keys() else ''