【发布时间】:2017-09-27 13:29:05
【问题描述】:
我意识到有很多相关的主题,但我似乎无法找到一个相同的和/或包含解决我问题的解决方案。
我正在向 dompdf 发送一个 HTML 文档,其中包括嵌入的 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 类的任何元素的字体都是正确的,在检查器中,当我调用以下命令时,它还显示它正在使用网络资源在 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 格式从正确应用的其余规则中得到正确应用,但字体除外。
老实说,我不确定是否需要以其他方式安装这些字体,例如使用命令行 load_font.php 第三方库。根据我对 0.8.0 版本的理解,我不需要,对吗?
有什么建议或意见吗?
【问题讨论】:
-
以防万一有人遇到同样的问题,但这不是解决方法,如果您通过自签名证书通过 HTTPS 访问字体,您也会遇到此问题。在@font-face src 中使用 http:// 将修复它。