Hi all.
I am a big fan of ODT templates. I think that it is the best way to give your personal touch to your documents. Unfortunately ODT management is not very evolved even in version 6 and there are a lot of issues with it. But in my V5 install I did manage to put all pieces to work and I got a functional PDF document generation using the prefered JODconverter mechanism.
Now V6 came out. As I could not afford breaking my V5 install just to upgrade to V6, I started from scratch and created a new server with Centos Web Panel to handle the hosting part. I copied the V5 database to this new install and ran the upgrade procedure. So I got a clean V6 install with my old V5 data upgraded. So far so god.
But this approach had the drawback of not having installed the JOD part of the equation and it turned out to be quite difficult to find anything JOD related tested under Centos 7 because the developement of the JOD converter looks like stopped long time ago.
So I turned my eyes to the alternate method that dolibarr offer based on python and found that it looked a lot more easy to setup that the JOD one. Thus I started putting pieces into place and, now, I have a functional ODT to PDF conversion mechanism based on the python alternative. And using this approach you need not to have any java in your system if you do not want to.
So I though that I could share with you what I did just in case you find it useful and would like to give it a try.
The first thing you have to do is to go and find the code for the DocumentConverter.py script. Put this script in the dolibarr/scripts/odt2pdf folder side by side with the odt2pdf.sh file. You can chmod it to 444 if you want to be strcit regarding security and you should change the owner to whatever your apache server is running when you run the dolibarr app.
Just in case you do not find the script or do not want to modify the bash file I have attached the ones I am using. Make a copy of your original files prior to making any changes to have a return route. Take care of making the bash script executable if you copy the attached one.
Now you have to make a small change to odt2pdf.sh in order for everything to go fine: the line where you call the python script must be changed so that the full path to the script is used or it will not be found because the context where the script is being run is the one of the process (invoice, shipment, quuote, etc.) you are running not the one of the bash script. My script already has that line updated and it also has some other lines that spit some info to a file named ‘pyconvert.log’ located in /tmp. This way every conversion made I have a log of what has happened and can see the errors if any.
If you managed (or peferred) to download the python script, you will have to change the port used to connect with Libreoffice (by the way: you aready have Libreoffice installed, righ?). The python script uses port 2002 and you have to change this to port 8100 as the odt2pdf.sh script loads the office library listening to that other port. Change it whenever you like, one place or the other, but make sure that both point to the same value.
If you use my script there are also other additions to the python file to spit some messages as the process flow. If you do not want those messages set the DEBUG variable to 0.
Now you need to tell dolibarr to use the python script. Login as admin user (or as user that has access to the setup area of the menu) and go to ‘Other Setup’. You should have a ‘MAIN_ODT_AS_PDF’ variable listed there. Assign it a value of ‘pyodconverter’.
Now your dollibarr install should be starting to use the python script to convert your templates into PDF files. In my case, sometimes, the front-end did not update and finished showing an error screen. I had to restart apache to be able to make the program work again.
To avoid this you must protect the script execution from exceptions and any other unexpected behaviors. So go to dolibarr/htdocs/includes/odtphp and edit the odf.php file. Wrap line 957 (where the script is launched from by an ‘exec($command, …’ ) in a try/catch block like this:
try {
exec($command, $output_arr, $retval);
} catch (Exception $e) {}
After doing that I stopped to have to restart the apache service just to get my documents shown (they were truly generated but the screen got locked until the apache restart).
Hope this is useful to someone
Regards.
Miguel.