Sunday, March 21, 2010

[Solved] DocumentConverter.py via PHP on Linux RedHat Centos


This is a guide to fix the use of PYODConverter on linux RedHat Centos 5 box users.
If you wanna use DocumentConverter.py written by artofsolving, you have to follow those steps.

1)Install openoffice on your linux box or verify installation through commands:
Install Packages

yum install openoffice.org-xxx.

Check Packages

yum list | grep "openoffice".


2)Install python-uno bridge

3)Download DocumentConverter.py

4)Add the following line below "import uno"...

import sys
sys.path.append("/usr/lib/openoffice.org/program")


5)Run openoffice like a service with -headless and -nofirtstartwizard options.


/usr/lib/openoffice.org/program/soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;"




The port 8100 must be the same for client and server obviously.


If you execute this php code



$cmd = "/usr/bin/python /var/www/html/DocumentConverter.py inputfile $outputfile.pdf 2>&1 | tee /var/www/html/mylog.txt"; // tee used to log output and errors of cmd
exec($cmd, $results);
printf("Exec Output: {".print_r($results).";}\n"); //print results of exec command


you'll probably get this error:


[Java framework] Error in function createSettingsDocument (elements.cxx).javaldx failed!

And other permissions problems on tmp dirs.

To solve this, simply add into your php script those lines of code

if (!file_exists("/tmp/ooohomedir"))
{
mkdir("/tmp/ooohomedir");
chmod("/tmp/ooohomedir", 0777);
}
putenv("HOME=/tmp/ooohomedir");







If you have another workaround about this please leave a comment below.
C u.

No comments: