Better error message in convert odt to pdf

This commit is contained in:
Laurent Destailleur 2019-04-27 17:31:14 +02:00
parent 9fc523bca7
commit 3c90461502

View File

@ -584,7 +584,7 @@ IMG;
// using windows libreoffice that must be in path // using windows libreoffice that must be in path
// using linux/mac libreoffice that must be in path // using linux/mac libreoffice that must be in path
// Note PHP Config "fastcgi.impersonate=0" must set to 0 - Default is 1 // Note PHP Config "fastcgi.impersonate=0" must set to 0 - Default is 1
$command ='soffice -headless -convert-to pdf -outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name); $command ='soffice --headless --convert-to pdf --outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
} }
elseif (preg_match('/unoconv/', $conf->global->MAIN_ODT_AS_PDF)) elseif (preg_match('/unoconv/', $conf->global->MAIN_ODT_AS_PDF))
{ {
@ -635,6 +635,7 @@ IMG;
//$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name.' '.$dirname; //$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name.' '.$dirname;
dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG); dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG);
$retval=0; $output_arr=array();
if ($execmethod == 1) if ($execmethod == 1)
{ {
exec($command, $output_arr, $retval); exec($command, $output_arr, $retval);
@ -665,6 +666,7 @@ IMG;
if ($retval == 0) if ($retval == 0)
{ {
dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
$filename=''; $linenum=0;
if (headers_sent($filename, $linenum)) { if (headers_sent($filename, $linenum)) {
throw new OdfException("headers already sent ($filename at $linenum)"); throw new OdfException("headers already sent ($filename at $linenum)");
} }
@ -681,16 +683,17 @@ IMG;
} }
} else { } else {
dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG); dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr, true), LOG_DEBUG);
if ($retval==126) { if ($retval==126) {
throw new OdfException('Permission execute convert script : ' . $command); throw new OdfException('Permission execute convert script : ' . $command);
} }
else { else {
$errorstring='';
foreach($output_arr as $line) { foreach($output_arr as $line) {
$errors.= $line."<br>"; $errorstring.= $line."<br>";
} }
throw new OdfException('ODT to PDF convert fail : ' . $errors); throw new OdfException('ODT to PDF convert fail (option MAIN_ODT_AS_PDF is '.$conf->global->MAIN_ODT_AS_PDF.', command was '.$command.', retval='.$retval.') : ' . $errorstring);
} }
} }
} }