I am using laravel-dompdf on my system to output pdfs.
I recently updated php and laravel.
However, some of the pdf's are garbled.
Font is defined by font-face in css.
The font-face is defined in public/assets/pdf.css.
Characters enclosed in <th> are garbled.
Characters with font-weight of "bold" are also garbled.
Why is this?
The .a class defined in public/assets/pdf.css. is reflected.
It was working without garbled characters in php7.4.33 and laravel6.20.44 before the update.
I heard from a friend that two font-face definitions are needed to support bold in utf-8, so I defined two font-face definitions, but they are not reflected.
The .a class defined in public/assets/pdf.css. is reflected.
public/assets/pdf.css
.a {
font-size: 80px;
}
html {
font-size: 10px;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
@font-face {
font-family: mcs;
src: url('../fonts/mcs.TTF');
}
@font-face {
font-family: mcs;
font-weight: bold;
font-style: bold;
src: url('../fonts/mcs.TTF');
}
body {
font-family: ipag;
font-weight: normal !important;
}
resources/views/pdf.blade.php
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="{{ public_path('/assets/pdf.css') }}" rel="stylesheet" type="text/css" media="all">
<style>
</style>
</head>
<body>
<table>
<tr>
<th>カタカナ</th>
<td>カタカナ</td>
</tr>
<tr>
<th>漢字</th>
<td>漢字</td>
</tr>
<tr>
<th>ひらがな</th>
<td>ひらがな</td>
</tr>
</table>
<p class="a">あいうえお</p>
<p style="font-weight: bold">あいうえお<p>
</body>
</html>
function in controller
$export = $this->pdf->loadView('pdf');
return $export->download('test.pdf');
The TTF file exists without problems in public/fonts/mcs.TTF.
sh-4.2# php -v
PHP 8.1.23 (cli) (built: Sep 15 2023 21:56:29) (NTS)
sh-4.2# php artisan --version
Laravel Framework 9.52.16
and I have installed the mbstring extension.
yum install php-mbstring
Output pdf
I updated barryvdh/laravel-dompdf to 1.0.0 and a little later it improved. It is not known why it improved.