Automatically generate PDF documents from ODT file
Prerequisites
- Have installed the open source software LibreOffice if it is not already done on the server.
Configuration
In Dolibarr
- Connect with an administrator account
- In Home, Configuration, Miscellaneous => Add the variable "MAIN_ODT_AS_PDF" with the value "libreoffice"
If Linux server, on the server
Nothing special to do beyond the installation of libreoffice.
If Windows server (example with DoliWamp), on the server
- In the Windows control panel, Search for "modify system environment variables"
- In the dialog box, click on environment variables at the bottom right.
- In system variables go to "Path" and press modify
- Click on add to add a line and browse to the LibreOffice installation folder "C:\Program Files\LibreOffice\program" (the place where soffice is installed)
- Edit the odf.php files which are by default in:
C:\dolibarr\www\dolibarr\htdocs\includes\odtphp\odf.php
Search and Replace this line below:
$command ='soffice --headless -env:UserInstallation=file:"//'.$conf->user->dir_temp.'" --convert-to pdf --outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
By:
$command ='soffice --headless "//'.$conf->user->dir_temp.'" --convert-to pdf --outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
Save the file
- Edit the bootstrap.ini file again, which is located by default in:
C:\Program Files\LibreOffice\program\bootstrap.ini
[Bootstrap]
InstallMode=<installmode>
ProductKey=LibreOffice 7.1
//Replace this line with:
UserInstallation=file:///C:/ProgramData/LibreOffice/4
Save the file
Restart the doliwampmysqld and doliwampapache services or restart the computer.
Usage
Once the configuration is done, the PDF generation is enabled and will be done automatically by converting the ODT file to PDF after each generation of an ODT document from its template. The 2 types of files (ODT / PDF) will be present when generating a document. If there is an error on the ODT template, the PDF will not be generated.
Option to keep only the PDF file
In Dolibarr:
- Connect to Dolibarr with an administrator account
- In Home, Configuration, Miscellaneous => Add the variable "MAIN_ODT_AS_PDF_DEL_SOURCE" with the value "1"