drkrsx3135168 2018-02-08 03:14
浏览 147

Dompdf-Laravel不使用Unicode字符

I'm using Laravel 5.5 with DOMPDF its work fine for English but not working for Unicode it's always output ???? symbol to me

Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PDF;

class PdfController extends Controller
{
    public function export(){
        $data['title']="Print Report";
        $pdf = PDF::loadView('pdf.invoice', $data);
        return $pdf->download('invoice.pdf');
    }
}

Blade

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        @font-face {
            font-family: khmer;
            font-style: normal;
            font-weight: 400;
            src: url({{asset('fonts/khmer.ttf')}}) format('true-type');
        }
    </style>

</head>
<body>
    កម្ពុជាក្រោម
</body>
</html>

Result ?????????

  • 写回答

3条回答 默认 最新

  • douxi1968 2018-02-08 15:52
    关注

    I was trying to solve similar problem in my application what I've done is I've transformed view with mb_convert_encoding function.

    In your case I would to sth like that:

        $data['title']="Print Report";
        $pdf = mb_convert_encoding(\View::make('pdf.invoice', $data), 'HTML-ENTITIES', 'UTF-8'));
        return PDF::loadHtml($pdf)->download('invoice.pdf');
    

    Also be careful with font settings. Your needs to support UTF-8 charset.

    评论

报告相同问题?