【问题标题】:bold font weight not working with Google fonts in dompdf粗体字重不适用于 dompdf 中的 Google 字体
【发布时间】:2020-04-24 04:45:09
【问题描述】:

我正在使用 dompdf 将 HTML 代码转换为 pdf。我正在使用 Google 字体并像这样导入它们:

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800&display=swap');

当我在我的 CSS 中使用它们时:

    h1, h3, .text {
      font-family: 'Open Sans';
      font-weight: 400;
    }

我的文字字体正确。现在,当某些文本像标题或某些粗体文本一样是粗体时,它们不会获得正确的字体粗细。当我将字体粗细更改为 400 以上时,它们不再起作用。

有人知道如何在 dompdf 中使用多种字体粗细吗?

【问题讨论】:

    标签: css dompdf google-webfonts


    【解决方案1】:

    Dompdf 0.8.4 发布之前,不支持数字字体粗细。如果您使用的是 0.8.4 之前的 Dompdf 版本,则不能使用使用数字权重定义的字体。

    此外,虽然支持数字字体粗细,但在使用 @import 规则时,Dompdf 解析 Google 字体 URL 的方式似乎存在错误。 (参考issue 2054)。您可以改用链接元素来解决此问题。

    类似下面的东西应该可以工作:

    <html>
    <head>
    
      <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800&display=swap" rel="stylesheet">
    
      <style>
        .opensans {
          font-family: 'Open Sans';
          font-weight: 400;
        }
    </style>
    
    </head>
    
    <body>
      <h1 class="opensans">The quick red fox jumped over the large brown log.</h1>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2014-07-02
      • 2016-09-27
      • 2014-07-07
      • 1970-01-01
      • 2019-08-06
      • 2014-11-16
      • 2021-08-06
      • 2011-04-27
      • 2020-09-27
      相关资源
      最近更新 更多