Skip to content

Commit

Permalink
Merge pull request #29 from frederic34/workdev
Browse files Browse the repository at this point in the history
manage error
  • Loading branch information
frederic34 authored Feb 6, 2024
2 parents 4f95076 + 1e01b4b commit 149bd91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
48 changes: 27 additions & 21 deletions core/modules/propale/doc/doc_easydoc_propale_html.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* \ingroup propal
* \brief File of class to build PDF documents for propales
*/

use NumberToWords\NumberToWords;

require_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php';
Expand Down Expand Up @@ -559,28 +560,33 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails

$infile = $filetomerge_dir . $linefile->file_name;
if (file_exists($infile) && is_readable($infile)) {
// stop adding header on every page
$mpdf->SetHeader();
$mpdf->Bookmark($linefile->file_name);
// This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI
// Alternatively the document you're trying to import has to be resaved without the use of compressed cross-reference streams
// and objects by an external programm (e.g. by lowering the PDF version to 1.4).
$pagecount = $mpdf->setSourceFile($infile);
for ($i = 1; $i <= $pagecount; $i++) {
$tplIdx = $mpdf->importPage($i);
if ($tplIdx !== false) {
$s = $mpdf->getTemplatesize($tplIdx);
// array (size=5)
// 'width' => float 210.00155555556
// 'height' => float 296.99655555556
// 0 => float 210.00155555556
// 1 => float 296.99655555556
// 'orientation' => string 'P' (length=1)
$mpdf->AddPage($s['height'] > $s['width'] ? 'P' : 'L');
$mpdf->useTemplate($tplIdx);
} else {
setEventMessages(null, [$infile . ' cannot be added, probably protected PDF'], 'warnings');
try {
$pagecount = $mpdf->setSourceFile($infile);
// stop adding header on every page
$mpdf->SetHeader();
$mpdf->Bookmark($linefile->file_name);
// This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI
// Alternatively the document you're trying to import has to be resaved without the use of compressed cross-reference streams
// and objects by an external programm (e.g. by lowering the PDF version to 1.4).
for ($i = 1; $i <= $pagecount; $i++) {
$tplIdx = $mpdf->importPage($i);
if ($tplIdx !== false) {
$s = $mpdf->getTemplatesize($tplIdx);
// array (size=5)
// 'width' => float 210.00155555556
// 'height' => float 296.99655555556
// 0 => float 210.00155555556
// 1 => float 296.99655555556
// 'orientation' => string 'P' (length=1)
$mpdf->AddPage($s['height'] > $s['width'] ? 'P' : 'L');
$mpdf->useTemplate($tplIdx);
} else {
setEventMessages(null, [$infile . ' cannot be added, probably protected PDF'], 'warnings');
}
}
} catch (Exception $e) {
setEventMessage($langs->trans('EasydoCantAddPdfToDoc', $linefile->file_name), 'errors');
setEventMessage($e->getMessage(), 'errors');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function info($langs)
// List of directories area
$text .= '<tr><td>';
$texttitle = $langs->trans("ListOfDirectoriesForHtmlTemplates");
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->TICKET_ADDON_EASYDOC_TEMPLATES_PATH)));
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString('TICKET_ADDON_EASYDOC_TEMPLATES_PATH'))));
$listoffiles = [];
foreach ($listofdir as $key => $tmpdir) {
$tmpdir = trim($tmpdir);
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/easydocgenerator.lang
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ EASYDOC_PDF_FORMAT=Format papiers
EasydocStopTheBillAtSumOf=Arrêté la facture à la somme de : %s
EasydocStopTheOrderAtSumOf=Arrêté la commande à la somme de : %s
EasydocStopThePropalAtSumOf=Arrêté la proposition commerciale à la somme de : %s
EasydoCantAddPdfToDoc=Easydocgenerator ne peux pas ajouter le fichier %s au document

0 comments on commit 149bd91

Please sign in to comment.