# 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 `