mpdf / mpdf.github.io

mPDF documentation
https://mpdf.github.io
Other
504 stars 160 forks source link

Custom font is not working in Arabic Language #179

Closed shimul49 closed 2 years ago

shimul49 commented 2 years ago

In mPDF 8.1 (along with Laravel 9), I am trying to use Cairo Font. I write the following code:

$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];

$mpdf = new Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4-L',
    'setAutoTopMargin' => 'pad',
    'fontDir' => array_merge($fontDirs, [
        public_path('fonts') . '/cairo/',
    ]),
    'fontdata' => $fontData + [
        'cairo' => [
            'R' => 'Cairo-Regular.ttf',
            'B' => 'Cairo-Bold.ttf',
        ]
    ],
    'default_font' => 'cairo'
]);

// For Arabic Report
if( trim($type) == 'arabic' ) {
    $mpdf->baseScript = 1;
    $mpdf->autoScriptToLang = true;
    $mpdf->autoLangToFont = true;
    $mpdf->autoArabic = true;
}

When I export the PDF with Arabic content, I notice the Cairo font is not used in the content. Surprisingly if I export the report using English content then the Cairo font is working perfectly. So, I assume this is some sort of issue related to Arabic.

N.B: The font supports Arabic so there is no issue related to the font itself.

shimul49 commented 2 years ago

Ask in wrong repo.