dompdf加载自定义字体有时显示乱码

时间:2017-05-19 05:36:13

标签: php laravel dompdf custom-font

Sample output

这是输出,右边应该是这样的

Expected output

大部分时间它都正确打印出来,但有时候它没有显示正确的字符

这是我的代码

@font-face {
    font-family: 'street';
    src: url('{{ URL::to('/assets/fonts/street/street.eot') }}');
    src: url('{{ URL::to('/assets/fonts/street/street.eot?#iefix') }}') format('embedded-opentype'),
         url('{{ URL::to('/assets/fonts/street/street.woff2') }}') format('woff2'),
         url('{{ URL::to('/assets/fonts/street/street.woff') }}') format('woff'),
         url('{{ URL::to('/assets/fonts/street/street.ttf') }}') format('truetype'),
         url('{{ URL::to('/assets/fonts/street/street.svg#street') }}') format('svg');
    font-weight: normal;
    font-style: normal;
}

.hollow{font-family:street}

<font class="hollow" style="font-size:3em;line-height:200%;text-transform:uppercase;display:block;margin:0;position:absolute;top:5px;left:0;right:0;text-align:center">{{str_replace($shop_name_cleaner , '' , $company_name) }}</font>
<font class="hollow" style="{{(strlen($company_name) > 30) ? 'font-size:1.8em;top:81px' : 'font-size:1.8em;top:60px'}};text-transform:uppercase;margin:-29px 0 0 0;vertical-align:top;display:block;position:absolute;left:0;right:0;text-align:center">RESIT PAJAK</font>

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:0)

使用选项类设置utf-8编码和自定义字体。

    $options = new Options();
    $options->set('defaultFont', 'DejaVu Sans');
    $dompdf = new Dompdf($options);