php - dompdf 0.7.0 beta 的粗体字体

标签 php html css dompdf

我正在使用 DOMPDF 版本。 0.7.0 从 HTML 制作 pdf 文件,但是当我需要使用粗体样式的自定义字体(arial)时我遇到了问题。粗体字体在渲染后将不起作用。

这是我现在使用的 CSS 样式:

@font-face {
    font-family: 'font';
    font-style: normal;
    font-weight: normal;
    src: url(dompdf/font/arial.ttf);
}

@font-face {
    font-family: 'font';
    font-style: normal;
    font-weight: bold;
    src: url(dompdf/font/arialbd.ttf);
}
body{
    font-family: 'font';
}

这是 dompdf - php 代码:

require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents('pdf/sptjm.pdf', $pdf)

这是 HTML 格式的结果: enter image description here

这是 PDF 格式的结果: enter image description here

pdf 没有显示粗体,请帮助。提前致谢。

最佳答案

我只是通过使用不同的字体名称来做到这一点:

@font-face {
    font-family: 'font';
    font-style: normal;
    font-weight: normal;
    src: url(dompdf/font/arial.ttf);
}

@font-face {
    font-family: 'font2';
    font-style: normal;
    font-weight: bold;
    src: url(dompdf/font/arialbd.ttf);
}
body{
    font-family: 'font';
}

所以当我需要粗体字体类型时,只需简单地调用其他字体名称,因为基本上它是不同的字体源。

关于php - dompdf 0.7.0 beta 的粗体字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37506023/

相关文章:

php - 如何实现多人浏览器游戏?

php - 将 PHP 查询设置为嵌套数组

PHP - mySql 查询执行两次

html - 下拉菜单 Bootstrap 代码

java - 替换JSP中的HTML特殊字符

javascript - 将内容限制为单个打印页面的想法?

css - Gmail 应用程序 (Android) 上的响应式电子邮件 - rem 和 heights

php - Laravel 5.2 获取Linux系统环境变量

html - 以正确的宽高比调整图像大小的 CSS 水平菜单

html - 是否可以禁用 textarea 的多行选项?