Laravel DomPdf Add Custom Font

本小妞迷上赌 提交于 2019-12-06 11:25:02

问题


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.

Thanks In Advance.


回答1:


  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
    }
    
  4. Add font-family rules to your css as seen below

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

Hope this helps.




回答2:


I was trying to include custom fonts too. I included the font in the view (using @font-face declaration), but when I tried to generate the pdf, it gave me an ErrorException in AdobeFontMetrics.php. I resolved by creating a fonts folder in the storage folder of your laravel project. So now I have:

> storage
    > app
    > fonts
    > framework
    > logs

I hope it will help




回答3:


Set font into html page which is load in Dompdf
    <html>
    <head>
      <style>
      @font-face {
        font-family: 'Helvetica';
        font-weight: normal;
        font-style: normal;
        font-variant: normal;
        src: url("font url");
      }
      body {
        font-family: Helvetica, sans-serif;
      }
      </style>
    </head>
    <body>
      <p>hello world</p>
    </body>
    </html>


来源:https://stackoverflow.com/questions/43636379/laravel-dompdf-add-custom-font

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!