TCPDF通过CSS font-family设置字体

时间:2016-06-11 09:31:46

标签: html css fonts tcpdf font-family

我正在使用最新版本的TCPDF,并发现在使用font-family方法时我无法使用CSS writeHtml设置字体。设置字体的唯一方式是我使用SetFont,但这对我来说不会很好,因为文档需要有多个字体并且模板是使用一个创建的HTML视图文件。

到目前为止,这是模板文件:

<style media="all">
    html, body, p, h1, h2, h3, td, span {
        font-family: 'HeavyDisplay' !important;
        font-size: 10pt;
    }
</style>

<table cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td style="font-size:27pt;color:#2998ff">Tax Receipt</td>
        <td rowspan="2">Company Name</td>
    </tr>
    <tr>
        <td style="font-size:7pt;letter-spacing:.8pt;color:#999">&nbsp;<br>Please retain for income tax purposes</td>
    </tr>
</table>

我可以确认font-size属性有效。

此外,我尝试为每个标记内联font-family属性,但这没有任何区别。

这是TCPDF的错误吗?

1 个答案:

答案 0 :(得分:1)

请不要使用图书馆TCPDF或使用<style>标记或css文件的其他人

<style media="all">
    html, body, p, h1, h2, h3, td, span {
        font-family: 'HeavyDisplay' !important;
        font-size: 10pt;
    }
</style>

最好使用样式属性代替<style>代码或css文件

<body style="font-family: 'HeavyDisplay' !important;font-size: 10pt;"></body>
相关问题