【问题标题】:Laravel DomPDF Custom Font Face Shows Square BoxesLaravel DomPDF 自定义字体显示方形框
【发布时间】:2021-11-22 21:25:30
【问题描述】:

我正在尝试使用 dompdf 生成包含中文字符的 PDF,因此我下载了字体包并在我的 Blade.php 中添加了以下代码。

    @font-face {
        font-family: 'simhei';
        font-style: normal;
        font-weight: normal;
        src: url('{{base_path().'/public/fonts/'}}'simhei.ttf) format('truetype');
    }

    body {  
        font-family: 'simhei', 'DejaVu Sans', sans-serif; 
    }

接下来,我用 Postman 再次尝试了 API。响应正文显示如下所示的方框。

但如果我突出显示文本,它会显示中文字符。

如果我将响应保存为 Postman 中的文件,当我在 WPS Office 中打开它时,它也会显示方框而不是汉字。 我也尝试过其他字体包,包括 Firefly Sung 和 msyh。都给出相同的结果。

【问题讨论】:

  • 此错误表示字体支持字符的问题,但当字体文件嵌入 PDF 时,它缺少引用的字形。如果禁用字体子集 ($dompdf = new Dompdf(['isFontSubsettingEnabled' => false]);),字符是否正确显示?
  • 我从这个链接得到了解决方法:github.com/barryvdh/laravel-dompdf/issues/…

标签: laravel postman font-face dompdf


【解决方案1】:

试试这个:

@font-face {
      font-family: 'Firefly Sung';
      font-style: normal;
      font-weight: 400;
      src: url(http://eclecticgeek.com/dompdf/fonts/cjk/fireflysung.ttf) format('truetype');
    }
    * {
      font-family: Firefly Sung, DejaVu Sans, sans-serif;
    }

【讨论】:

猜你喜欢
  • 2019-07-15
  • 2020-06-12
  • 1970-01-01
  • 1970-01-01
  • 2012-09-16
  • 1970-01-01
  • 2017-08-28
  • 2017-09-28
  • 1970-01-01
相关资源
最近更新 更多