DomPDF 中的自定义字体

Custom Fonts in DomPDF

我在让自定义字体在 DOMPDF 中工作时遇到问题。我正在使用 Drupal 7 作为我的后端,但我认为这与我遇到的问题并不特别相关。当我 return 直接 HTML 时,我的自定义字体有效:

<?php
$HTML = <<<HTML

<!DOCTYPE html>
<html>
<head>

<style>

@font-face {
font-family: 'PressStart2PRegular';
    src: url('http://fontlibrary.org/assets/fonts/press-start-2p/6b0a4bbcec8eb53940cbfcb409a788ee/74496d9086d97aaeeafb3085e9957668/PressStart2PRegular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
  }

</style>
</head>

<body>
<p><span class="fa fa-envelope"></span> envelope</p>
<span style="font-family: 'PressStart2PRegular'">THwabubu Thwabubu thwabubu</span>
<p style="font-family: PressStart2PRegular;">dsafda</p>
</body>
</html>

HTML;

echo $HTML;
?>

但是,当我 return 使用 DOMPDF 库时,我的自定义字体不适用:

<?php
$HTML = <<<HTML

<!DOCTYPE html>
<html>
<head>

<style>

@font-face {
font-family: 'PressStart2PRegular';
src: url('http://fontlibrary.org/assets/fonts/press-start-2p/6b0a4bbcec8eb53940cbfcb409a788ee/74496d9086d97aaeeafb3085e9957668/PressStart2PRegular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

</style>
</head>

<body>
<p><span class="fa fa-envelope"></span> envelope</p>
<span style="font-family: 'PressStart2PRegular'">THwabubu Thwabubu thwabubu</span>
<p style="font-family: PressStart2PRegular;">dsafda</p>
</body>
</html>

HTML;

//DomPDF Stuffs
require_once "sites/all/libraries/dompdf/autoload.inc.php";
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->load_html($HTML);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream();
?>

根据我在 DOMPDF 文档中阅读的内容和这个答案:Dompdf and set different font-family 我觉得我正在使用 DOMPDF 中自定义字体的可接受参数进行操作,但我很清楚,出了点问题.我正在使用 DOMPDF 版本 0.8.0。我知道这与其他问题非常相似......但我无法弄清楚为什么这个实例不起作用。

这是一个权限问题。一旦我更改了 DomPDF 库文件夹的权限以使其可写,我的字体开始按预期工作。