diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index d4b79af8013..a13a3923eab 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -486,11 +486,14 @@ IMG; $execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2 - $name=str_replace('.odt', '', $name); - if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT)) { - $command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.$name; - }else { - $command = '../../scripts/odt2pdf/odt2pdf.sh '.$name; + $name=preg_replace('/\.odt/i', '', $name); + if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT)) + { + $command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.$name.' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF); + } + else + { + $command = '../../scripts/odt2pdf/odt2pdf.sh '.$name.' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF); } @@ -620,7 +623,7 @@ IMG; public function getvalue($valuename) { $searchreg="/\\[".$valuename."\\](.*)\\[\\/".$valuename."\\]/"; - preg_match($searchreg, $this->contentXml, $matches); + preg_match($searchreg, $this->contentXml, $matches); $this->contentXml = preg_replace($searchreg, "", $this->contentXml); return $matches[1]; } diff --git a/scripts/odt2pdf/odt2pdf.sh b/scripts/odt2pdf/odt2pdf.sh index c7c768a1244..b44ab3e6d78 100755 --- a/scripts/odt2pdf/odt2pdf.sh +++ b/scripts/odt2pdf/odt2pdf.sh @@ -1,30 +1,27 @@ #!/bin/bash -# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com -# @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro +# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com +# @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro +# @copyright GPL License 2015 - Laurent Destailleur - eldy@users.sourceforge.net # -# Convert an ODT into a PDF using "jodconverter" tool. -# Dolibarr variable MAIN_ODT_AS_PDF must be defined to have this script called after ODT generation. +# Convert an ODT into a PDF using "jodconverter" or "pyodconverter" tool. +# Dolibarr variable MAIN_ODT_AS_PDF must be defined to value "jodconverter" to call jodconverter wrapper after ODT generation +# or value "pyodconverter" to call DocumentConverter.py after ODT generation. +# or value "/pathto/jodconverter-cli-file.jar" to call jodconverter java tool without wrapper after ODT generation. # Dolibarr variable MAIN_DOL_SCRIPTS_ROOT must be defined to path of script directories (otherwise dolibarr will try to guess). -#if [ -f "$1.odt" ] -# then -# soffice --invisible --convert-to pdf:writer_pdf_Export --outdir $2 "$1.odt" -# retcode=$? -# if [ $retcode -ne 0 ] -# then -# echo "Error while converting odt to pdf: $retcode"; -# exit 1 -# fi -# else -# echo "Error: Odt file does not exist" -# exit 1 -#fi +if [ "x$1" == "x" ] +then + echo "Usage: odt2pdf.sh fullfilename [jodconverter|pyodconverter|pathtojodconverterjar]" + echo "Example: odt2pdf.sh myfile ~/jodconverter/jodconverter-cli-2.2.2.jar" + exit +fi + if [ -f "$1.odt" ] then nbprocess=$(pgrep -c soffice) - if [ $nbprocess -ne 1 ] + if [ $nbprocess -ne 1 ] # If there is some soffice process running then soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless & retcode=$? @@ -35,7 +32,19 @@ if [ -f "$1.odt" ] fi sleep 2 fi - jodconverter "$1.odt" "$1.pdf" + + if [ "x$2" == "xjodconverter" ] + then + jodconverter "$1.odt" "$1.pdf" + else + if [ "x$2" == "xpyodconverter" ] + then + python DocumentConverter.py "$1.odt" "$1.pdf" + else + java -jar $2 "$1.odt" "$1.pdf" + fi + fi + retcode=$? if [ $retcode -ne 0 ] then @@ -44,6 +53,6 @@ if [ -f "$1.odt" ] fi sleep 1 else - echo "Error: Odt file does not exist" + echo "Error: Odt file $1.odt does not exist" exit 1 fi