Search code examples
laravelutf-8dompdf

Laravel dompdf not showing japanese characters


I am using Laravel 5.4 and barryvdh/laravel-dompdf plugin for dompdf. I am using this code,

Controller

 $pdf = PDF::loadView('invoice');

View (invoice.blade.php)

<!DOCTYPE html>
<html>
<head>
    <title>Invoice</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>빨간색</div>
</body>
</html>

When using this code the japanese text will not show correctly. How do I fix this issue?


Solution

  • You can use this link for the answer. It is in japanese but you can use google chrome translate.

    In Summary:

    1. Download font file from http://ipafont.ipa.go.jp/old/ipafont/download.html or use any ttf files you want
    2. Download load_font.php file from https://github.com/dompdf/utils to /vendor/dompdf/dompdf/
    3. execute #php load_font.php ipag $path_to_font_directory/ipag.tt which will generate something like

    Unable to find bold face file.
    Unable to find italic face file.
    Unable to find bold_italic face file.
    Copying $path_to_font_directory/ ipag.ttf to $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag.ttf...
    Generating Adobe Font Metrics for $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag...

    1. Copy font files to storage #cp lib/fonts/* /storage/fonts/
    2. Reference your font in css

    body {
    font-family: ipag;
    }