#AskMe

Khmer Text on PDF, Works on mPDF

Here, how the story could explain in this result


As you see, it’s working!

mPDF (https://github.com/mpdf/mpdf) is originally extended from FPDF (http://fpdf.org/)

It has some wrapper such as in Laravel and other PHP framework.

To make it works, we need to understand how to put the custom font and in mPDF it has a configuration (I did in Laravel, wrapper using: https://github.com/niklasravnsborg/laravel-pdf) in “config/pdf.php” to provide a font configure as:

"yourfont" => /* Khmer */
  'R' => "your-regularfont.ttf",
  'useOTL' => 0xFF, // required for Khmer
  'useKashida' => 75, // required for Khmer
],

That’s it but if you don’t know how it works, you will end up using wrong font. Most of case, Khmer Fonts are missing Latin characters, you need to know to check this, here is example of missing character:

I did make an answer in 2012 for FPDF at StackOverflow when it that time, it’s hard to make it work even showing a Khmer character but it kept a clue to help with: http://www.fpdf.org/makefont/

With above makefont URL, it helps us to find a good font to use, in my case, it’s “Khmer OS Siemreap“, you test that you will see like this:

It’s a good font to use.

I think, it would work the same for library: TCPDF (https://tcpdf.org/) as it’s also an extender from FPDF.

Wrap-up

To make it works for mPDF:

1. HTML header to add:

2. Custom Font

3. Use fontname in HTML tag

That’s all!