Laravel DomPdf添加自定义字体 [英] Laravel DomPdf Add Custom Font

查看:259
本文介绍了Laravel DomPdf添加自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel在Dompdf中使用OLD英文字体. 我已经在laravel视图中插入了字体.但是似乎在生成pdf时不起作用.我尝试编辑dompdf >vendor >.../dompdf_font_family_cache.dist.php文件.但是没有运气,

I am trying to use OLD English font in Dompdf with Laravel., I have inserted the font in laravel view. But it seems when generating the pdf It is not working.I tried editing dompdf >vendor >.../dompdf_font_family_cache.dist.php File.But no luck,

任何人都可以提出解决方案吗?

Can anyone Suggest a Solution?

谢谢.

推荐答案

  1. 在Laravel项目的存储文件夹中创建一个字体目录. (存储空间/字体)
  2. 将.otf或.ttf文件放在storage/fonts目录中.
  3. 在您的视图/html中,使用Laravel提供的storage_path方法添加@ font-face规则.

  1. Make a fonts directory in the storage folder of your Laravel project. ( storage/fonts )
  2. Put your .otf or .ttf files in the storage/fonts directory.
  3. In your view/html add @font-face rules by using the storage_path method Laravel provides.

@font-face {
    font-family: 'Your custom font name';
    src: url({{ storage_path('fonts\your-custom-font.ttf') }}) format("truetype");
    font-weight: 400; // use the matching font-weight here ( 100, 200, 300, 400, etc).
    font-style: normal; // use the matching font-style here
}

  • 将字体家族规则添加到css中,如下所示

  • Add font-family rules to your css as seen below

    body {
        font-family: "Your custom font name";
    }
    

  • 希望这会有所帮助.

    这篇关于Laravel DomPdf添加自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆