From 2b210b4bb8e5c0ffee7c1218f99fb891c75f80a9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sun, 20 Sep 2020 15:39:53 +0200 Subject: [PATCH] Fixed issue with PDF being generated without a name (#333) --- classes/template.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/classes/template.php b/classes/template.php index 688574b..b97cefb 100644 --- a/classes/template.php +++ b/classes/template.php @@ -283,6 +283,16 @@ class template { $pdf->SetAutoPageBreak(true, 0); // Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename. $filename = rtrim($this->name, '.'); + + // This is the logic the TCPDF library uses when processing the name. This makes names + // such as 'الشهادة' become empty, so set a default name in these cases. + $filename = preg_replace('/[\s]+/', '_', $filename); + $filename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $filename); + + if (empty($filename)) { + $filename = get_string('certificate', 'customcert'); + } + $filename = clean_filename($filename . '.pdf'); // Loop through the pages and display their content. foreach ($pages as $page) { @@ -305,9 +315,13 @@ class template { } } } + + + if ($return) { return $pdf->Output('', 'S'); } + $pdf->Output($filename, 'D'); } }