简体   繁体   English

如何在DomPDF中安装自定义字体

[英]How to install a custom Font in DomPDF

Good day all. 大家好。

Im using WordPress and DomPDF to create a simple posts to pdf to email function. 我使用WordPress和DomPDF创建了一个简单的文章,以pdf到电子邮件功能。

The PDF generation and email function is working fine however, I dont seem to be able to get a custom font working at all. PDF生成和电子邮件功能运行良好,但是,我似乎根本无法获得自定义字体。

Ive downloaded the .ttf file from Google (Muli-Regular.ttf) and am trying to add it in as follows: 我已经从Google(Muli-Regular.ttf)下载了.ttf文件,并尝试将其添加如下:

<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
<style type="text/css">  
    @font-face{
        font-family: 'Muli';
        src:'<?php echo get_template_directory(); ?>/dompdf/lib/fonts/Muli.ttf';
    }      
    h1,h2,h3,h4,h5 {
        font-family: 'Muli', sans-serif;
    }
    h1.title{ color: #6c9bcb !important}
    p, a{font-size: 16px;font-family: 'Muli', sans-serif;}
    footer a{color: #333;}     
</style>

Needless to say, the PDF is not loading the font. 不用说,PDF不会加载字体。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Your @font-face declaration doesn't conform to the CSS spec. 您的@font-face声明不符合CSS规范。 The main issue is the src property, the path isn't wrapped in the url function. 主要问题是src属性,该路径未包装在url函数中。 Also, dompdf can be a bit finicky so best to be as explicit as possible. 另外,dompdf可能有点挑剔,因此最好尽可能明确。 Try this: 尝试这个:

@font-face {
  font-family: 'Muli';
  font-style: normal;
  font-weight: normal;
  src: url('<?php echo get_template_directory(); ?>/dompdf/lib/fonts/Muli.ttf') format('truetype');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM