Add hidden option MAIN_ODT_AS_PDF to save ODT as PDF (only if

libreoffice/jodconverter/exec shell right)
This commit is contained in:
fhenry 2013-04-20 10:44:01 +02:00
parent 62c9366d69
commit 413ee7ec78
7 changed files with 70 additions and 18 deletions

View File

@ -519,8 +519,12 @@ class doc_generic_order_odt extends ModelePDFCommandes
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Write new file
//$result=$odfHandler->exportAsAttachedFile('toto');
$odfHandler->saveToDisk($file);
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
}
else {
$odfHandler->saveToDisk($file);
}
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -497,8 +497,12 @@ class doc_generic_invoice_odt extends ModelePDFFactures
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Write new file
//$result=$odfHandler->exportAsAttachedFile('toto');
$odfHandler->saveToDisk($file);
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
}
else {
$odfHandler->saveToDisk($file);
}
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -650,7 +650,7 @@ class doc_generic_project_odt extends ModelePDFProjects
//Time ressources
$sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
$sql.= ", u.name, u.firstname";
$sql.= ", u.lastname, u.firstname";
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
$sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE t.fk_task =".$task->id;
@ -973,8 +973,12 @@ class doc_generic_project_odt extends ModelePDFProjects
// Write new file
$odfHandler->saveToDisk($file);
//$odfHandler->exportAsAttachedPDF($file);
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
}
else {
$odfHandler->saveToDisk($file);
}
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -482,8 +482,12 @@ class doc_generic_proposal_odt extends ModelePDFPropales
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Write new file
//$result=$odfHandler->exportAsAttachedFile('toto');
$odfHandler->saveToDisk($file);
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
}
else {
$odfHandler->saveToDisk($file);
}
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -313,8 +313,12 @@ class doc_generic_odt extends ModeleThirdPartyDoc
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Write new file
//$result=$odfHandler->exportAsAttachedFile('toto');
$odfHandler->saveToDisk($file);
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
$odfHandler->exportAsAttachedPDF($file);
}
else {
$odfHandler->saveToDisk($file);
}
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -450,10 +450,39 @@ IMG;
{
if( $name == "" ) $name = md5(uniqid());
$this->saveToDisk("$name.odt");
exec("./odt2pdf.sh $name",$output,$ret_val);
if($ret_val == 0)
{
dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
$this->saveToDisk($name);
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name;
dol_syslog('$execmethod='.$execmethod.' Run command='.$command);
if ($execmethod == 1)
{
exec($command, $output_arr, $retval);
}
if ($execmethod == 2)
{
$ok=0;
$handle = fopen($outputfile, 'w');
if ($handle)
{
dol_syslog("Run command ".$command);
$handlein = popen($command, 'r');
while (!feof($handlein))
{
$read = fgets($handlein);
fwrite($handle,$read);
$output_arr[]=$read;
}
pclose($handlein);
fclose($handle);
}
if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
}
if($retval == 0)
{
dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
if (headers_sent($filename, $linenum)) {
throw new OdfException("headers already sent ($filename at $linenum)");
}
@ -464,9 +493,12 @@ IMG;
unlink("$name.odt");
unlink("$name.pdf");
} 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);
echo "Error occured:<br>";
foreach($output as $line)
foreach($output_arr as $line)
echo $line."<br>";
dol_syslog(get_class($this).'::exportAsAttachedPDF ERROR $line='.$line, LOG_DEBUG);
}
}

4
htdocs/includes/odtphp/odt2pdf.sh Normal file → Executable file
View File

@ -1,7 +1,7 @@
#!/bin/bash
# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
if [ -f "$1.odt" ]
if [ -f $1 ]
then
pgrep -U `id -u` soffice
if [ $? -ne 0 ]
@ -9,7 +9,7 @@ then
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
sleep 2
fi
jodconverter "$1.odt" "$1.pdf"
jodconverter $1 "$1.pdf"
if [ $? -ne 0 ]
then
echo "Error while converting odt to pdf"