DOMPDF 设置整个页面的字体?

发布于 2024-08-20 05:05:33 字数 487 浏览 5 评论 0原文

我在 http://dompdf.github.com/ 使用 DOMPDF

我正在努力如何设置字体整个页面。在我制作的模板中,我在 CSS 中将字体设置为 Helvetica,但当它生成 PDF 时,它默认为 Times New Roman。 当我尝试时

<script type="text/php">{literal}if ( isset($pdf) ) { 
    $font = Font_Metrics::get_font("helvetica", "bold");
    $pdf->page_text(72, 18, "TEST!", $font, 6, array(0,0,0));}
{/literal}</script>

它会打印测试!字体中的文字。但是如何才能将其应用到整个页面呢?

谢谢

Im using DOMPDF over at http://dompdf.github.com/

I am struggling how to set the font for the entire page. In the template I have made I have the font set to Helvetica in the CSS but when it generates the PDF it defaults to Times New Roman.
When I try

<script type="text/php">{literal}if ( isset($pdf) ) { 
    $font = Font_Metrics::get_font("helvetica", "bold");
    $pdf->page_text(72, 18, "TEST!", $font, 6, array(0,0,0));}
{/literal}</script>

It prints the TEST! text in the font. However how do I get it to apply to the whole page?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

洛阳烟雨空心柳 2024-08-27 05:05:33

DOMPDF 使用 CSS,因此您需要像这样设置字体系列:

body {  
    font-family: 'Helvetica'  
}

但请记住,您只能使用已安装的字体。要检查可以使用哪些字体,请查看字体目录:/dompdf/lib/fonts/

要安装更多字体,请按照以下指南操作:
http://code.google.com/p/dompdf/wiki/Installation#Font_Installation

DOMPDF works with CSS so you need to set the font family like so:

body {  
    font-family: 'Helvetica'  
}

BUT remember that you can only use the font that have been installed. To check which fonts you can use have a look in the fonts directory: /dompdf/lib/fonts/

To install more font follow this guide:
http://code.google.com/p/dompdf/wiki/Installation#Font_Installation

无所谓啦 2024-08-27 05:05:33

DOMPDF 支持 CSS,因此您只需在 CSS 文件中定义字体并像平常在页面上一样加载它:

body {
    font-family: 'Helvetica'
}

DOMPDF supports CSS, so you can just define the font in your CSS file and load it like you normally would on a page:

body {
    font-family: 'Helvetica'
}
薄荷梦 2024-08-27 05:05:33

我也有同样的问题。不知何故,DomPDF 在 CSS 中的字体系列定义方面遇到了麻烦。我将内联样式应用于顶部 div 框来解决该问题。

<div id="container" style="font-family:sans-serif;">
....
</div>

希望这对仍在阅读该主题的任何人都有效。

I had the same problem. Somehow DomPDF has trouble with the font-family definition in the CSS. I applied inline style to the top div box to solve the problem.

<div id="container" style="font-family:sans-serif;">
....
</div>

Hope this works for anyone still reading this thread.

感性 2024-08-27 05:05:33

您需要将 font-family 定义添加到 CSS 中的每个元素:

body, #wrapper, #content {
font-family:sans-serif;
}
table{
font-family:sans-serif;
}     
table tr{
font-family:sans-serif;
}    
table td{
font-family:sans-serif;
}        
a:link, a:visited {
font-family:sans-serif;
}
p {
font-family:sans-serif;
}

You need to add the font-family definition to every element in your CSS:

body, #wrapper, #content {
font-family:sans-serif;
}
table{
font-family:sans-serif;
}     
table tr{
font-family:sans-serif;
}    
table td{
font-family:sans-serif;
}        
a:link, a:visited {
font-family:sans-serif;
}
p {
font-family:sans-serif;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文