Printing Sinhala Unicode Receipts on Thermal Printers with html2canvas
Most thermal receipt printers cannot draw Sinhala characters, so receipts come out with broken or missing letters. This page explains how I fixed it for Agro Ledger, a settlement system for agricultural trade centers in Sri Lanka.
1The problem: printers do not understand Sinhala
Thermal printers have built-in fonts that cover basic Latin characters. Sinhala is a complex script where letters combine into ligatures, so sending it as plain text produces unreadable receipts.
2Render the receipt as an image
Instead of sending text, I render the receipt as HTML in the browser, where the font handles Sinhala shaping correctly, and convert it to a bitmap with html2canvas. The printer then receives an image over ESC/POS, so it only has to print dots.
3Wait for fonts before capturing
If the image is captured before the Sinhala font has loaded, ligatures come out wrong. I added a font-ready synchronisation step with a short rendering delay so the text is fully shaped before the capture happens.
- Render the receipt in HTML with a Sinhala-capable font
- Wait until the font is loaded and the layout settles
- Capture to a bitmap and send it to the printer
4Working without internet
Many trade centers have unreliable connections, so the system runs on a local Laragon or WAMP setup. I removed external CDN dependencies and bundled libraries such as SweetAlert and html2canvas locally.
5Tech stack
Laravel, PHP and MySQL on the back end, jQuery and Bootstrap 5 on the front end, html2canvas for rendering, and ESC/POS for printing.
Need something similar built?
I build and ship platforms like this for startups and retailers. Tell me what you are trying to launch and I will reply with how I would approach it.