diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php
index 66b58a8..1b7af1c 100644
--- a/app/Controllers/Ipd_discharge.php
+++ b/app/Controllers/Ipd_discharge.php
@@ -7363,43 +7363,49 @@ class Ipd_discharge extends BaseController
$mpdf->SetTitle('Discharge Summary - ' . ($patientName !== '' ? $patientName : ('IPD ' . $ipdId)));
$mpdf->SetAuthor('Atria HMS');
- // Build mPDF-style @page block + named header/footer wrappers (same as OPD template renderer).
- $marginTopCm = (float) ($templateSettings['page_margin_top_cm'] ?? 0.8);
- $marginBottomCm = (float) ($templateSettings['page_margin_bottom_cm'] ?? 0.8);
- $marginLeftCm = (float) ($templateSettings['page_margin_left_cm'] ?? 0.8);
- $marginRightCm = (float) ($templateSettings['page_margin_right_cm'] ?? 0.8);
- $marginHeaderCm = (float) ($templateSettings['margin_header_cm'] ?? 0.5);
- $marginFooterCm = (float) ($templateSettings['margin_footer_cm'] ?? 0.5);
+ // Build mPDF fragment following the exact structure from the mPDF docs:
+ // ' . "\n";
-
- $namedBlocks = '';
+ // Assemble exactly as shown in mPDF documentation: CSS → named blocks → content.
+ $pdfHtml = '' . "\n";
if ($useHeader) {
- $namedBlocks .= '' . "\n" . $headerHtml . "\n" . '' . "\n";
+ $pdfHtml .= '' . "\n" . $headerHtml . "\n" . '' . "\n";
}
if ($useFooter) {
- $namedBlocks .= '' . "\n" . $footerHtml . "\n" . '' . "\n";
+ $pdfHtml .= '' . "\n" . $footerHtml . "\n" . '' . "\n";
}
-
- // Single WriteHTML call: mPDF does not require full HTML document structure.
- $templateCss = trim((string) ($templateSettings['template_css'] ?? ''));
-
- $pdfHtml = $pageBlock
- . $namedBlocks
- . ($templateCss !== '' ? '' . "\n" : '')
- . $renderedHtml;
+ $pdfHtml .= $renderedHtml;
$pdfHtml = mpdf_normalize_font_weight_css($pdfHtml);
$pdfBinary = $this->runMpdfWithTolerantWarnings(static function () use ($mpdf, $pdfHtml, $fileName): string {
$mpdf->WriteHTML($pdfHtml);