【发布时间】:2016-07-29 14:16:36
【问题描述】:
我正在使用 dompdf 从输入生成 PDF。
我使用的代码:
require_once (STYLESHEETPATH.'/dompdf/include/autoload.inc.php');
set_include_path(STYLESHEETPATH.'/dompdf');
require_once STYLESHEETPATH.'/dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$html = '
<html>
<body>
<h1>Hello <i>'. $fullname.'</i> </h1>
<p> your father is <b>'.$fathername.'</b>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("tck.pdf"); ?>
这很好用并生成一个名为tck.pdf的pdf
现在我想为 pdf 中的字体设置样式,所以我尝试过
require_once (STYLESHEETPATH.'/dompdf/include/autoload.inc.php');
set_include_path(STYLESHEETPATH.'/dompdf');
require_once STYLESHEETPATH.'/dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$html = '
<html>
<head>
<style>
@font-face {
font-family: "Open Sans";
font-style: normal;
font-weight: 400;
src: url(http://themes.googleusercontent.com/static/fonts/opensans/v8/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf) format("truetype");
}
</style>
</head>
<body>
<h1>Hello <i>'. $fullname.'</i> </h1>
<p> your father is <b>'.$fathername.'</b>
<br/>
<span style="font-family:webfontregular;">bar code will be here</span>
<div style="font-family:"Open Sans";">Open Sans</div>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("tck.pdf"); ?>
但它不起作用并给出如下错误:
Fatal error: Class 'Font' not found in /home4/q0i4l0g2/public_html/tck/wp-content/themes/kallyas-child/dompdf/include/font_metrics.cls.php on line 356
我注意到,每当我使用“@font-face”时,我都会收到此错误。 这是为什么? 我怎样才能让它发挥作用?
根据这个问题Dompdf and set different font-family 中接受的答案,我认为这应该有效,但它没有。
【问题讨论】:
-
@Chris 不,不是......如果这些问题的答案解决了这个问题,那么这个问题就没有机会获得 4 次投票......
-
所以你是说你尝试过降级 php-font-lib?