I am using Dompdf to create a pdf for my Nepali content. I have written following code in my controller:
public function generatePDF(Request $request){
$data = $this->news->where('slug', $request->slug)->first();
$html = "<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta charset='UTF-8'>
<title>". $data->title ."</title>
<style>
@font-face {
font-family: preeti;
font-style: normal;
font-weight: 400;
src: url('{{ asset('/frontend/fonts/preeti.ttf') }}') format('truetype');
}
</style>
</head>
<body style='font-family: preeti;'>
<img src='".$data->image ."' style='width: 100%; height: auto'>
". $data->description ."
</body>
</html>";
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$pdf = PDF::setOptions(['dpi' => 150, 'defaultFont' => 'preeti']);
$pdf = PDF::loadHTML($html);
return $pdf->download('sample.pdf');
}
But this gives ???? as an output of the Nepali content inside the canvas. However, <title>". $data->title ."</title>
displays right character. What can I do to fix this?
As you can see I have kept UTF-8
in my meta
also have included CSS for the font but it does not seem to work. I have also included mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
but it made no change. Does anyone has fixed this kind of issue?
The output of $data->description
is
<p>????? ????????????? ????? ????? ??????? ????? ????????? ??????? ??? ????? ?
?????????????? ??? ? ??, ??? ????? ??????????? ???????? ?? ???????? ??? ?
<p>??????? ?????? ????? ?????, ???? ????? ?–????? ???????? ?????? ????? ?? ? ??????? ?? ???????????? ????? ?????? ????????? ?? ??????? ?????? ? ??? ??? ?? ?
<p>??????? ????? ????? ??? ?????? ?????? ?, ???? ??? ????? ????? ?????? ????? ???????? ? ????????? ????? ???? ?????? ??????? ???? ??????????? ??????? ????? ? ?? ?
<p>????????? ??? ???? ????????? ??? ? ??????? ??????? ??????? ????? ???????? ?????? ????????????? ?????? ???????? ???, ?????? ? ?????? ?????? ???? ?????? ?????? ?
<p><strong>???????? ????? ??????? ????</strong><br />????????? ??????????? ????? ????? ????????? ??????? ??????????? ? ????????? ??????? ???? ??? ? ????? ?????? ?
<p>????? ?????? ??? ??? ??????? ?? ???? ?????? ? ? ?????? ??? ???????? ???????? ? ????????? ???????? ??? ????; ???? ??? ???????? ?????? ????? ?????? ? ???? ???? ?
<p>??? ???, ?????????? ????? ?????????? ??????? ?? ????? ??? ? ????????? ?????????? ????? ?????? ???? ???? ???? ????? ???????? ????? ?? ????? ? ???????????????? ?
<p>?? ????????? ????? ?????? ?????? ????????? ??????????? ????? ????? ? ??????, ????? ???????? ???? ???? ????? ????? ?????? ??? ??? ?????? ????? ???? ? ??????? ?
<p>???????? ???? ????? ? ????? ?????? ??Œ?????? ???? ?????? ? ?????, ??????????? ????? ??????? ???????? ?????? ???????? ????? ? ?????? ??? ?, ?????? ????? ?
<p>????????? ????????? ???????? ?????? ???, ?????? ? ??????? ???? ?????? ???????? ??????????? ????????? ???? ????????? ???? ?????? ???? ? ??? ??????? ?????? &ls ?
<p><strong>????????</strong> ??? ?????? ??????????? ??????????? ???? ???? ???? ? ??????????? ????? ?????? ???? ???????? ???? ??????? ??? ? ??????????? ????? ??? ?
<p>??????? ?? ??????????? ????? ????? ????? ?????????? ????? ?????? ? ?????, ?????? ???????? ‘???????????? ????? ???? ?????????’ ? ? ??????, ???? ?? ?
<p><strong>????????? ???????????? ????? ??????</strong><br />??? ? ? ??? ?????? ????? ??????? ????? ? ? ??????? ???????? ??????? ? ???? ????????? ? ???? ???? ?? ?
<p>??????? ????????????? ????????? ??????–? ?? ????? ? ?????? ?????? ??? ??? ???????? ???? ??? ???? ?????? ??????????? ???????? ????? ??? ???? ????????? ? ?
<p>??????????? ???? ????? ??? ?????? ????? ?????? ????? ?????? ? ??????? ??????????? ???? ??? ???? ????????? ??? ??????????? ????? ???????? ?????????? ??¥?? ?
<p><strong>???????? ???? ‘??????’</strong><br />?????? ????? ?????? ? ?????????? ?????? ?????????? ??? ???? ????? ??????? ? ???????? ???? ????? ???? ?
<p>????? ????????? ??? ?? ????????? ????????? ??????? ??? ? ??? ??? ????????? ??????? ????? ????????? ??????? ???? ??????? ??, ??÷??? ????? ?????????? ?? ?
<p>????? ??? ???????? ?????????? ???? ???????? ? ????????? ???????????? ??????? ???? ????? ?????? ????? ? ? ?????????? ??? ???????? ??????? ???? ?????? ??? ??? ?
<p>???????? ?????? ????? ???? ????? ???????? ???? ??? ???? ????????? ???????? ???? ???? ?? ? ??, ????? ????? ????? ?? ?????? ???? ??????? ?????? ????? ???? ???? ?
<p>???????; ??????? ????????? ??? ???????? ????, ????? ????? ????????? ??????? ???? ????? ? ?????— ??????–? ?? ‘???? ????, ???? ????’ ?? ?
<p>????????? ???????????? ?????? ???? ????? ????? ??????????? ???? ??? ????? ? ? ?????? ???? ????? ????? ?? ?? ? ?????? ?????? ???? ????????? ? ?????, ?????? ?? ?
<p>???????????? ?????????? ???? ???????? ??????? ???? ??????? ?????? ??? ??? ???????, ??? ??? ??????? ? ??? ??? ????????????? ?????????? ?????? ??????? ????? ?? ?
<p><strong>??????? ?????? ?????</strong><br />????? ??????, ?? ‘???? ??????’ ?? ??????? ‘??????’ ????? ???? ???????? ??????? ? ????, ??? ?
<p>????? ???????? ??????????? ?????????? ?????? ????? ???? ????? ??????????? ? ?????????? ???? ? ???????? ???? ?????????? ??? ??????? ????????? ????? ?????? ??? ?
<p>?????? ?????????????? ?????, ?????????????? ??????? ???? ? ? ?? ?????? ??Œ?????? ???? ?? ? ??????? ????????????? ??????? ????? ????? ????? ???????? ?? ?
<p>??????? ????????????? ????? ???? ???? ?????? ? ????? ????? ??? ?????? ??? ?????? ??? ???? ??????? ????? ????? ? ? ????? ??????? ????? ???? ??????????? ????? ?
<p><em><strong>??????????????? ????????? ???????? ??????</strong></em></p>
See Question&Answers more detail:os