0

I write a simple code for rendering chinese words in pdf. But the chinese words does not appear.

This is my code.

Route::get('/pdf', function () {
    $html = '<html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                </head>
                <body>
                    <p style="font-family: firefly, DejaVu Sans, sans-serif;">献给母亲的爱</p>
                </body>
                </html>';
   $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML($html);
    return $pdf->stream();
});

I'm using

1) PHP 7.1.1
2) Laravel 5.3

I inserted the meta into the header and change the font. What might gone wrong here?please help thanks.

etzzz
  • 165
  • 1
  • 4
  • 15
  • Did you set the PHP header and check the file-encoding too? – Qirel May 10 '17 at 06:08
  • I check file-encoding for $html by using mb_detect_encoding($html) and it output UTF-8. For the header if you mean by header("Content-type:application/pdf"); , i try it and still not worked. – etzzz May 10 '17 at 06:15
  • anyone please help? – etzzz May 11 '17 at 17:00

2 Answers2

0

Turn out that default font provided within dompdf does not support chinese character. You have to insert your own custom fonts in order to display the chinese words. Refer here Insert Custom Font on how to insert and use custom fonts in dompdf.

etzzz
  • 165
  • 1
  • 4
  • 15
0

The better way is to use this package:

composer require vatttan/apdf

Documents

akbar
  • 625
  • 6
  • 12