From d87b38e7f04e61f384255258bfc4f60f23d42de8 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 18 Aug 2026 16:02:46 +0530 Subject: [PATCH] Add mPDF reference doc; fix discharge PDF rendering --- MPDF_REFERENCE.md | 292 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 MPDF_REFERENCE.md diff --git a/MPDF_REFERENCE.md b/MPDF_REFERENCE.md new file mode 100644 index 0000000..903af8e --- /dev/null +++ b/MPDF_REFERENCE.md @@ -0,0 +1,292 @@ +# mPDF Reference — HMS E-Atria Project + +Source: https://mpdf.github.io/ +Version used: mpdf/mpdf (composer, see vendor/) + +--- + +## 1. Core Pattern — Single WriteHTML Call (used in this project) + +mPDF does NOT require a full HTML document (``, ``, ``, ``). +Pass a plain HTML fragment to `WriteHTML()`. + +### Correct structure for a templated PDF with header/footer: + +``` + + + +
Hospital Name
+
+
+ + +
Page {PAGENO} of {nbpg}
+
+ +

Discharge Summary

+

Patient content here…

+``` + +**Rules:** +- `@page` block MUST be in a ` + + header_html (tokens replaced) + footer_html (tokens replaced) + rendered template body (template_html with tokens replaced) +5. $mpdf->WriteHTML($pdfHtml) +6. Output as binary PDF string → CI4 response +``` + +**Token replacement**: `{{TOKEN_NAME}}` or `{{token_name}}` — case-insensitive. +Available tokens: H_Name, H_logo_abs, PATIENT_NAME, UHID, IPD_CODE, ADMIT_DATE, +DISCHARGE_DATE, FINAL_DIAGNOSIS, SURGERY, DISCHARGE_MEDICATIONS, DISCHARGE_SUMMARY, +CONTENT (all sections), and many more — see placeholder list in template editor. + +**Debug**: `/Ipd_discharge/show_discharge/{ipdId}/1?tpl={tplId}&html=1` +Shows the exact HTML string passed to `WriteHTML()`. + +--- + +## 11. Common Issues and Fixes + +| Problem | Cause | Fix | +|---|---|---| +| Header not repeating on every page | Missing `header: html_myHeader` in `@page` | Add `header: html_myHeader;` to `@page` block in CSS textarea | +| CSS appears as visible text | CSS injected inside body `
`, not in `