字体在HTML中起作用,但不能渲染PDF DOMPDF V0.8.0



我意识到有很多相关的主题,但是我似乎找不到一个相同的主题,并且包括一个解决我的问题的解决方案。

我正在将HTML文档发送到DOMPDF,其中包括嵌入式CSS,并包括字体范围的声明和类定义。这些字体在同一台服务器上,我尝试使用相对路径和绝对路径,似乎无法使它们工作。

我将以下内容包括在HTML文档的头部,然后发送到DOMPDF。

<style type="text/css">
    @font-face {
        font-family: "Roboto";
        font-weight: normal;
        font-style: normal;
         src: url( "http://localhost/resources/fonts/Roboto/Roboto-Regular.ttf") format('truetype');
     }
      .font_alpha { font-family: "Roboto";}`
    /* .... Other css rules here ... */
</style>

当我回应HTML而不是将其发送到DOMPDF时,我可以看到,应用.font_alpha类的任何元素的字体正确,在Inspector中,它还表明它正在使用网络资源,但是当我调用以下内容时在HTML上,该字体不会应用。

//This is where I would display the html directly for testing
//echo $report_html; exit;
$dompdf = new DOMPDF();
$dompdf -> load_html( $report_html );
$dompdf -> set_paper( $this -> paper_size, $this -> paper_orientation );
$dompdf -> render();
$dompdf -> output();

PDF(s(通过所有CSS从正确应用的其余规则中正确生成,除了字体。

说实话,我不确定是否需要以其他方式安装这些字体,例如使用cmd line load_font.php thirdparty lib。根据我相信我可以理解0.8.0版本的内容,我不需要正确吗?

有任何建议或输入?

dompdf的CSS解析逻辑可能有点挑剔。URL字符串前面的空间正在向上绊倒DOMPDF。如果您修改CSS读取src: url("http...") format('truetype');,则应按预期工作。

最新更新