From 12c15fba0c09aa94939c1d7001e3e7d35959aefa Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 2 Feb 2016 15:28:42 +0100 Subject: [PATCH] Fix problem with PDF , the forced conversion to image and back to PDF doesnt work properly, it works better with ps2pdf and pdf2ps --- include/class/class_document_export.php | 21 ++++++++++++++++++--- include/constant.php | 21 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/include/class/class_document_export.php b/include/class/class_document_export.php index 2dfee92cd..50fa05967 100644 --- a/include/class/class_document_export.php +++ b/include/class/class_document_export.php @@ -168,10 +168,12 @@ class Document_Export //----------------------------------- // Fix broken PDF , actually pdftk can not handle all the PDF - if ( FIX_BROKEN_PDF == 'YES' ) { - $stmpt = CONVERT_GIF_PDF." ". escapeshellarg($this->store_convert . '/' . $file_pdf)." ". escapeshellarg($this->store_convert . '/' . $file_pdf.'tmp'); + if ( FIX_BROKEN_PDF == 'YES' && PDF2PS != 'NOT' && PS2PDF != 'NOT') { + + $stmpt = PDF2PS." ". escapeshellarg($this->store_convert . '/' . $file_pdf)." ". escapeshellarg($this->store_convert . '/' . $file_pdf.'.ps'); + passthru($stmpt,$status); - rename ($this->store_convert . '/' . $file_pdf.'tmp',$this->store_convert . '/' . $file_pdf); + if ($status <> 0) { $this->feedback[$cnt_feedback]['file'] = $this->store_convert . '/' . $file_pdf; @@ -180,6 +182,19 @@ class Document_Export $cnt_feedback++; continue; } + $stmpt = PS2PDF." ". escapeshellarg($this->store_convert . '/' . $file_pdf.'.ps')." ". escapeshellarg($this->store_convert . '/' . $file_pdf.'.2'); + + passthru($stmpt,$status); + + if ($status <> 0) + { + $this->feedback[$cnt_feedback]['file'] = $this->store_convert . '/' . $file_pdf; + $this->feedback[$cnt_feedback]['message'] = ' cannot force to PDF'; + $this->feedback[$cnt_feedback]['error'] = $status; + $cnt_feedback++; + continue; + } + rename ($this->store_convert . '/' . $file_pdf.'.2',$this->store_convert . '/' . $file_pdf); } // output $output = $this->store_convert . '/stamp_' . $file_pdf; diff --git a/include/constant.php b/include/constant.php index 655e629ec..fec5988af 100644 --- a/include/constant.php +++ b/include/constant.php @@ -44,7 +44,7 @@ if ( !defined("NOALYSS_PLUGIN")) define ("NOALYSS_PLUGIN",$g_ext_dir); if ( !defined("NOALYSS_INCLUDE")) define ("NOALYSS_INCLUDE",$g_include_dir); if ( !defined("NOALYSS_TEMPLATE")) define ("NOALYSS_TEMPLATE",$g_template_dir); // pdftk can deal with all the PDF , for some of them it is preferable to fix it -// with convert +// with convert , see also PDF2PS and PS2PDF if yes if ( !defined("FIX_BROKEN_PDF")) define ("FIX_BROKEN_PDF",'NO'); require_once NOALYSS_INCLUDE.'/constant.security.php'; @@ -236,7 +236,26 @@ if (file_exists($convert_gif_pdf)) define ('CONVERT_GIF_PDF','NOT'); } +/** + * PDF2PS is used when the PDF is broken , used with FIX_BROKEN_PDF + */ +$pdf2ps='/usr/bin/pdf2ps'; +if ( ! file_exists($pdf2ps) ) + define ('PDF2PS','NOT'); + else + define ('PDF2PS',$pdf2ps); +/** + * PS2PDF is used when the PDF is broken , used with FIX_BROKEN_PDF + */ +$ps2pdf='/usr/bin/ps2pdf'; + +if ( ! file_exists($ps2pdf) ) + define ('PS2PDF','NOT'); + else + define ('PS2PDF',$ps2pdf); + + /** * Outil pour manipuler les PDF */