amit028's avatar

laravel-dompdf thai language not working

Hello Guys,

I'm using barryvdh/laravel-dompdf version 0.8.6. When i'm trying to print THAI language, instead of showing thai text it is showing ????? . I tried with font THSarabunNew.ttf but doesn't work. This is my code -

ROUTE -

Route::get('/print', function () {
    $pdf = PDF::loadView('print');
    return @$pdf->stream();
})->name('print');

VIEW (print.blade.php)

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Laravel</title>
        <style>
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: normal;
            src: url("{{ asset('fonts/THSarabunNew.ttf') }}") format('truetype');
        }
        body {
            font-family: 'THSarabunNew';
        }
        </style>
    </head>
    <body>
        <h1>
            แดชบอร์ด
        </h1>
    </body>
</html>

Any suggestion would be highly appreciated.

0 likes
9 replies
amit028's avatar

Yes, I tried but didn't work.

For your information, i have copied /fonts folder within public, resources and storage directories just in case if it works.

this is font link - http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/

And those fonts are linked correct because if i am downloading that font on button click then it is downloading means it is linked correctly, right?

amit028's avatar

Hello @sinnbeck ,

The problem is little bit weird. Text is not rendering because of h1 tag, but if i am writing same text within p or span tags, then it is working. I have 30+ pages where i am using dompdf. Any idea why it is happening.

Working code

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Laravel</title>
        <style>
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: normal;
            src: url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNew.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: normal;
            src: url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewBold.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: normal;
            src: url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewBoldItalic.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: normal;
            src: url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewItalic.ttf') }}") format('truetype');
        }

        body {
            font-family: 'THSarabunNew';
        }
        </style>
    </head>
    <body>
        <h1>
            แดชบอร์ด    // not working
        </h1>
         
        <p>
            แดชบอร์ด   //working
        </p>
    </body>
</html>

Sinnbeck's avatar

That is indeed strange. Perhaps consider posting it as an issue on the github repo.

For now, a solution could be to replace the h1 tags with a styled div tag

1 like
amit028's avatar

Thank you @sinnbeck ,

It worked. This is the working code -

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Laravel</title>
        <style>
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: bold;
            src: local('Quattrocento Sans Bold'), local('QuattrocentoSans-Bold'),url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNew.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: bold;
            src: local('Quattrocento Sans Bold'), local('QuattrocentoSans-Bold'), url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewBold.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: bold;
            src: local('Quattrocento Sans Bold'), local('QuattrocentoSans-Bold'), url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewBoldItalic.ttf') }}") format('truetype');
        }
        @font-face {
            font-family: 'THSarabunNew';
            font-style: normal;
            font-weight: bold;
            src: local('Quattrocento Sans Bold'), local('QuattrocentoSans-Bold'), url("{{ asset('http://164.115.33.174/awards_opdc/assets/fonts/THSarabunNew/THSarabunNewItalic.ttf') }}") format('truetype');
        }

        body {
            font-family: 'THSarabunNew';
        }
        </style>
    </head>
    <body>
        <h1>
            แดชบอร์ด   {{-- NOW WORKING --}}
        </h1>
         
        <p>
            แดชบอร์ด    {{-- WORKING --}}
        </p>
    </body>
</html>

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Happy to help. Remeber to mark the thread as solved

2 likes
Abdullah_Iftikhar's avatar

@sinnbeck I am facing an issue with the multilanguage PDF export. I want Chinese export. But the out is ????? like this. Can you help me, please?

Please or to participate in this conversation.