Search code examples
csslaravelinternationalizationdompdf

Chinese characters on PDF (laravel-dompdf)


I'm trying to show some Chinese characteres in my PDF; but it is proving much more complicated than I had imagined.

I'm using the vendor laravel-dompdf and I tried with a lot of fonts like: Fyrefly Sung, SimHei, SimSun, Unifont as follow:

@font-face {
    font-family: SimHei;
    src: url('{{base_path()."/public/assets/fonts/fireflysung.ttf"}}') format('truetype');
}
.chinese{
    font: Arial 14px;
    line-height: 16px;
    font-family:  Firefly Sung;
}

As well with a CDN:

@font-face {
    font-family: 'Firefly Sung';
    font-style: normal;
    font-weight: 400;
    src: url(http://foo.bar/fireflysung.ttf) format('truetype');
}
.chinese{
    font: Arial 14px;
    line-height: 16px;
    font-family:  Firefly Sung;
}

Example:

<span class="chinese">不含弹性织物</span>

But I can't get it work, since my PDF shows other chinese characters:

ゴム部を除く

Solution

  • I have solved my problem:

    I remove the call of the output() method before call stream():

    // $pdf->output();
    return $pdf->stream($myPDFName);
    

    And now works as expected.