22
33/* For licensing terms, see /license.txt */
44
5- use Chamilo \CoreBundle \Component \Mpdf \SafeMpdfHttpClient ;
65use Chamilo \CoreBundle \Entity \GradebookCategory ;
76use Chamilo \CoreBundle \Entity \PersonalFile ;
87use Chamilo \CoreBundle \Entity \ResourceFile ;
@@ -1007,32 +1006,7 @@ public function generateCustomCertificate(string $fileName = ''): string
10071006 public function generatePdfFromCustomCertificate (): void
10081007 {
10091008 $ orientation = api_get_setting ('certificate.certificate_pdf_orientation ' );
1010-
1011- $ pdfOrientation = 'landscape ' ;
1012- if (!empty ($ orientation )) {
1013- $ pdfOrientation = $ orientation ;
1014- }
1015-
1016- $ pageFormat = 'landscape ' === $ pdfOrientation ? 'A4-L ' : 'A4 ' ;
1017-
1018- // Instanciate mPDF directly to avoid blank pages generated by the default
1019- // PDF class: format_pdf() sets mirrorMargins=1 (book layout) and the
1020- // constructor hard-codes margin_header=8 / margin_footer=8 even when
1021- // headers and footers are empty, which causes mPDF to insert blank
1022- // odd/even pages around the single certificate page.
1023- $ mpdf = new \Mpdf \Mpdf ([
1024- 'tempDir ' => Container::getCacheDir (),
1025- 'mode ' => 'utf-8 ' ,
1026- 'format ' => $ pageFormat ,
1027- 'orientation ' => $ pdfOrientation ,
1028- 'margin_left ' => 0 ,
1029- 'margin_right ' => 0 ,
1030- 'margin_top ' => 0 ,
1031- 'margin_bottom ' => 0 ,
1032- 'margin_header ' => 0 ,
1033- 'margin_footer ' => 0 ,
1034- ], SafeMpdfHttpClient::container ());
1035- $ mpdf ->mirrorMargins = 0 ;
1009+ $ pdfOrientation = !empty ($ orientation ) ? $ orientation : 'landscape ' ;
10361010
10371011 // Safety: ensure HTML content is present; fetch from Resource if needed.
10381012 if (empty ($ this ->certificate_data ['file_content ' ])) {
@@ -1048,11 +1022,14 @@ public function generatePdfFromCustomCertificate(): void
10481022 }
10491023 }
10501024
1051- @$ mpdf ->WriteHTML ((string ) $ this ->certificate_data ['file_content ' ]);
1052-
1053- $ pdfName = api_replace_dangerous_char (get_lang ('Certificates ' ));
1054- $ mpdf ->Output ($ pdfName .'.pdf ' , \Mpdf \Output \Destination::DOWNLOAD );
1055- exit ;
1025+ // Single-page render with SSRF-guarded mPDF lives in the PDF class; it
1026+ // skips format_pdf()'s book layout to avoid blank pages around the
1027+ // single certificate page.
1028+ PDF ::singlePageHtmlToPdfDownload (
1029+ (string ) $ this ->certificate_data ['file_content ' ],
1030+ get_lang ('Certificates ' ),
1031+ $ pdfOrientation
1032+ );
10561033 }
10571034
10581035 /**
0 commit comments