Skip to content

Commit

Permalink
Merge pull request #5616 from christianbeeznest/ofaj-21812-2
Browse files Browse the repository at this point in the history
Internal: Disable pagination in certificate PDF generation - refs BT#21812
  • Loading branch information
christianbeeznest authored Jun 26, 2024
2 parents 5348023 + fb657d0 commit a92ac86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions public/main/inc/lib/certificate.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ public function generatePdfFromCustomCertificate(): void
false,
true,
true,
true,
true
);
}
Expand Down
41 changes: 18 additions & 23 deletions public/main/inc/lib/pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public function content_to_pdf(
$returnHtml = false,
$addDefaultCss = false,
$completeHeader = true,
$disableFooter = false
$disableFooter = false,
$disablePagination = false
) {
$urlAppend = '';

Expand All @@ -400,7 +401,7 @@ public function content_to_pdf(

// Formatting the pdf
$courseInfo = api_get_course_info($courseCode);
self::format_pdf($courseInfo, $completeHeader);
self::format_pdf($courseInfo, $completeHeader, $disablePagination);
$document_html = preg_replace($clean_search, '', $document_html);

//absolute path for frames.css //TODO: necessary?
Expand Down Expand Up @@ -476,8 +477,6 @@ public function content_to_pdf(

if ($addDefaultCss) {
$basicStyles = [
//api_get_bootstrap_and_font_awesome(true, true),
//api_get_path(SYS_PUBLIC_PATH).'build/css/app.css',
api_get_path(SYS_PUBLIC_PATH).'build/css/themes/'.api_get_visual_theme().'/default.css',
];
foreach ($basicStyles as $style) {
Expand Down Expand Up @@ -730,23 +729,15 @@ public function set_custom_footer($footer)
* @param array $courseInfo General course information (to fill headers)
* @param bool $complete Whether we want headers, footers and watermark or not
*/
public function format_pdf($courseInfo, $complete = true)
public function format_pdf($courseInfo, $complete = true, $disablePagination = false)
{
$courseCode = null;
if (!empty($courseInfo)) {
$courseCode = $courseInfo['code'];
}

/*$pdf->SetAuthor('Documents Chamilo');
$pdf->SetTitle('title');
$pdf->SetSubject('Exported from Chamilo Documents');
$pdf->SetKeywords('Chamilo Documents');
*/
// TODO: To be read from the html document.
$this->pdf->directionality = api_get_text_direction();
//$this->pdf->useOnlyCoreFonts = true;
$this->pdf->onlyCoreFonts = true;
// Use different Odd/Even headers and footers and mirror margins
$this->pdf->mirrorMargins = 1;

// Add decoration only if not stated otherwise
Expand All @@ -755,7 +746,6 @@ public function format_pdf($courseInfo, $complete = true)
if ('true' == api_get_setting('pdf_export_watermark_enable')) {
$watermark_file = self::get_watermark($courseCode);
if ($watermark_file) {
//http://mpdf1.com/manual/index.php?tid=269&searchstring=watermark
$this->pdf->SetWatermarkImage($watermark_file);
$this->pdf->showWatermarkImage = true;
} else {
Expand All @@ -781,17 +771,22 @@ public function format_pdf($courseInfo, $complete = true)
}
}

if (empty($this->custom_header)) {
self::set_header($courseInfo);
if ($disablePagination) {
$this->pdf->SetHTMLHeader('');
$this->pdf->SetHTMLFooter('');
} else {
$this->pdf->SetHTMLHeader($this->custom_header, 'E');
$this->pdf->SetHTMLHeader($this->custom_header, 'O');
}
if (empty($this->custom_header)) {
self::set_header($courseInfo);
} else {
$this->pdf->SetHTMLHeader($this->custom_header, 'E');
$this->pdf->SetHTMLHeader($this->custom_header, 'O');
}

if (empty($this->custom_footer)) {
self::set_footer();
} else {
$this->pdf->SetHTMLFooter($this->custom_footer);
if (empty($this->custom_footer)) {
self::set_footer();
} else {
$this->pdf->SetHTMLFooter($this->custom_footer);
}
}
}
}
Expand Down

0 comments on commit a92ac86

Please sign in to comment.