Better management for ODT to PDF
This commit is contained in:
parent
e6f9c567d9
commit
ee4839c92e
@ -520,10 +520,20 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
||||||
$odfHandler->exportAsAttachedPDF($file);
|
try {
|
||||||
|
$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
|||||||
@ -498,10 +498,20 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
||||||
$odfHandler->exportAsAttachedPDF($file);
|
try {
|
||||||
|
$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
|||||||
@ -974,10 +974,20 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
||||||
$odfHandler->exportAsAttachedPDF($file);
|
try {
|
||||||
|
$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
|||||||
@ -483,10 +483,20 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
||||||
$odfHandler->exportAsAttachedPDF($file);
|
try {
|
||||||
|
$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
|||||||
@ -314,10 +314,20 @@ class doc_generic_odt extends ModeleThirdPartyDoc
|
|||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
|
||||||
$odfHandler->exportAsAttachedPDF($file);
|
try {
|
||||||
|
$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
}catch (Exception $e){
|
||||||
|
$this->error=$e->getMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
|||||||
@ -452,14 +452,17 @@ IMG;
|
|||||||
|
|
||||||
if( $name == "" ) $name = md5(uniqid());
|
if( $name == "" ) $name = md5(uniqid());
|
||||||
|
|
||||||
//dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
|
dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
|
||||||
$this->saveToDisk($name);
|
$this->saveToDisk($name);
|
||||||
|
|
||||||
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
|
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
|
||||||
|
|
||||||
$name=str_replace('.odt', '', $name);
|
$name=str_replace('.odt', '', $name);
|
||||||
$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name;
|
$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name;
|
||||||
|
|
||||||
|
//$dirname=dirname($name);
|
||||||
|
//$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);
|
||||||
if ($execmethod == 1)
|
if ($execmethod == 1)
|
||||||
{
|
{
|
||||||
@ -471,7 +474,7 @@ IMG;
|
|||||||
$handle = fopen($outputfile, 'w');
|
$handle = fopen($outputfile, 'w');
|
||||||
if ($handle)
|
if ($handle)
|
||||||
{
|
{
|
||||||
dol_syslog("Run command ".$command);
|
dol_syslog(get_class($this)."Run command ".$command,LOG_DEBUG);
|
||||||
$handlein = popen($command, 'r');
|
$handlein = popen($command, 'r');
|
||||||
while (!feof($handlein))
|
while (!feof($handlein))
|
||||||
{
|
{
|
||||||
@ -492,19 +495,25 @@ IMG;
|
|||||||
throw new OdfException("headers already sent ($filename at $linenum)");
|
throw new OdfException("headers already sent ($filename at $linenum)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||||
header('Content-type: application/pdf');
|
header('Content-type: application/pdf');
|
||||||
header('Content-Disposition: attachment; filename="'.$name.'.pdf"');
|
header('Content-Disposition: attachment; filename="'.$name.'.pdf"');
|
||||||
readfile("$name.pdf");
|
readfile("$name.pdf");
|
||||||
}*/
|
}
|
||||||
unlink("$name.odt");
|
unlink("$name.odt");
|
||||||
} 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);
|
||||||
echo "Error occured:<br>";
|
|
||||||
foreach($output_arr as $line)
|
if ($retval==126) {
|
||||||
echo $line."<br>";
|
throw new OdfException('Permission execute convert script : ' . $command);
|
||||||
//dol_syslog(get_class($this).'::exportAsAttachedPDF ERROR $line='.$line, LOG_DEBUG);
|
}
|
||||||
|
else {
|
||||||
|
foreach($output_arr as $line) {
|
||||||
|
$errors.= $line."<br>";
|
||||||
|
}
|
||||||
|
throw new OdfException('ODT to PDF convert fail : ' . $errors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,41 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
|
# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
|
||||||
|
# @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro
|
||||||
|
|
||||||
|
#
|
||||||
|
#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 [ -f "$1.odt" ]
|
if [ -f "$1.odt" ]
|
||||||
then
|
then
|
||||||
pgrep -U `id -u` soffice
|
nbprocess=$(pgrep -c soffice)
|
||||||
if [ $? -ne 0 ]
|
if [ $nbprocess -ne 1 ]
|
||||||
then
|
then
|
||||||
soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless &
|
soffice --invisible --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard --headless
|
||||||
|
retcode=$?
|
||||||
|
if [ $retcode -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "Error running soffice: $retcode"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
fi
|
fi
|
||||||
jodconverter "$1.odt" "$1.pdf"
|
jodconverter "$1.odt" "$1.pdf"
|
||||||
if [ $? -ne 0 ]
|
retcode=$?
|
||||||
|
if [ $retcode -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "Error while converting odt to pdf"
|
echo "Error while converting odt to pdf: $retcode"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user