Skip to content

Commit

Permalink
Suggest better change for #8196. To be tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 15, 2018
1 parent f1a9f81 commit d547d1a
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions htdocs/includes/odtphp/odf.php
Expand Up @@ -561,7 +561,7 @@ public function exportAsAttachedFile($name="")
* Convert the ODT file to PDF and export the file as attached file by HTTP
* Note: you need to have JODConverter and OpenOffice or LibreOffice installed and executable on the same system as where this php script will be executed. You also need to chmod +x odt2pdf.sh
*
* @param string $name (optional)
* @param string $name Name of ODT file to generate before generating PDF
* @throws OdfException
* @return void
*/
Expand All @@ -577,7 +577,23 @@ public function exportAsAttachedPDF($name="")
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
// Method 1 sometimes hang the server.

if (preg_match('/unoconv/', $conf->global->MAIN_ODT_AS_PDF))

// Export to PDF using LibreOffice
if ($conf->global->MAIN_ODT_AS_PDF == 'libreoffice')
{
// Executing convert to PDF using libreoffice 5
if (isset($_SERVER["WINDIR"]))
{
// using windows libreoffice that must be in path
$command ='soffice.exe -headless -convert-to pdf -outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
}
else
{
// using linux/mac libreoffice that must be in path
$command ='soffice -headless -convert-to pdf -outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
}
}
elseif (preg_match('/unoconv/', $conf->global->MAIN_ODT_AS_PDF))
{
// If issue with unoconv, see https://github.com/dagwieers/unoconv/issues/87

Expand Down Expand Up @@ -609,16 +625,16 @@ public function exportAsAttachedPDF($name="")
else
{
// deprecated old method
$name=preg_replace('/\.odt/i', '', $name);
$tmpname=preg_replace('/\.odt/i', '', $name);

if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT))
{
$command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($name).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
$command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
}
else
{
dol_syslog(get_class($this).'::exportAsAttachedPDF is used but the constant MAIN_DOL_SCRIPTS_ROOT with path to script directory was not defined.', LOG_WARNING);
$command = '../../scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($name).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
$command = '../../scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
}
}

Expand Down Expand Up @@ -661,12 +677,15 @@ public function exportAsAttachedPDF($name="")
}

if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$name=preg_replace('/\.od(x|t)/i', '', $name);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$name.'.pdf"');
readfile("$name.pdf");
readfile($name.".pdf");
}
if (!empty($conf->global->MAIN_ODT_AS_PDF_DEL_SOURCE))
unlink("$name.odt");
{
unlink($name);
}
} else {
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);
Expand Down

0 comments on commit d547d1a

Please sign in to comment.