From f60011273b5074a3c0d859ba91e00b0f2e899164 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Fri, 5 May 2023 09:40:10 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20fonction=20statique=20afin=20de?= =?UTF-8?q?=20simplifier=20le=20code=20de=20cr=C3=A9ation=20de=20PDF=20dan?= =?UTF-8?q?s=20les=20applications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ src/UnicaenPdf/Exporter/PdfExporter.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb556f..58e989a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,18 @@ CHANGELOG ========= +6.0.1 +----- +- Ajout d'une fonction statique afin de simplifier le code de création de PDF dans les applications. + 6.0.0 ----- - Version PHP 8. +5.0.2 +----- +- Ajout d'une fonction statique afin de simplifier le code de création de PDF dans les applications. + 5.0.1 ----- - Reprise manuelle des dernières évolutions de l'Exporter dans unicaen/app diff --git a/src/UnicaenPdf/Exporter/PdfExporter.php b/src/UnicaenPdf/Exporter/PdfExporter.php index ed9149b..d7ab1b0 100644 --- a/src/UnicaenPdf/Exporter/PdfExporter.php +++ b/src/UnicaenPdf/Exporter/PdfExporter.php @@ -6,6 +6,7 @@ use Laminas\View\Renderer\PhpRenderer; use Laminas\View\Resolver\TemplatePathStack; use LogicException; use Mpdf\Mpdf as mPDF; +use Mpdf\MpdfException; use RuntimeException; /** @@ -867,4 +868,20 @@ class PdfExporter implements ExporterInterface $this->logo = $logoFileContent; return $this; } + + /** Fonction d'export d'un pdf générique pour factoriser le code côté application */ + static public function generatePdf(string $filename, string $titre, string $corps, + string $headerScript = '', string $footerScript = '', array $vars = []) : string + { + try { + $exporter = new PdfExporter(); + $exporter->getMpdf()->SetTitle($titre); + $exporter->setHeaderScript($headerScript, null, $vars); + $exporter->setFooterScript($footerScript, null, $vars); + $exporter->addBodyHtml($corps); + return $exporter->export($filename); + } catch(MpdfException $e) { + throw new RuntimeException("Un problème lié à MPDF est survenue",0,$e); + } + } } -- GitLab