【问题标题】:How to add Baamini Font in Dompdf and also add logo in pdf如何在 Dompdf 中添加 Baamini 字体并在 pdf 中添加徽标
【发布时间】:2020-04-17 20:54:46
【问题描述】:

我想在 Dompdf 中添加 Baamini 字体,并且我想在 dompdf 中添加页眉和页脚 我的控制器:

 $FileName = 'Test.pdf';
    if(isset($request->hidden_html)){$data['hidden_html']=$request->hidden_html;}
     $html = '<link rel="stylesheet" href="bootstrap.min.css">';
     $html.="<style>table th,table td{border-collapse: collapse;border: 1px solid rgba(0, 0, 0, .5);text-align: center;padding: 10px;font-size:12px!important;}table {width: 100%;margin-bottom: 1rem;color: #212529;border-collapse: collapse;} @page {margin: 0cm 0cm;}body {margin-top: 3cm; margin-left: 2cm;margin-right: 2cm;margin-bottom: 2cm;}header {position: fixed;top: 0cm;left: 0cm;right: 0cm;height: 3cm;}footer {position: fixed; bottom: 0cm; left: 0cm; right: 0cm;height: 2cm;@font-face{font-family: Baamini;  src: url(http://projectname(example)/css/Baamini.ttf) format('truetype');}.tamilfont{font-family: Baamini!important;}</style>";
     $html .= $data['hidden_html'];

     $pdf = new Dompdf();
     $pdf->set_option('defaultFont', 'Courier');

     $pdf->load_html($html);
     $pdf->render();
     $pdf->stream($FileName, array("Attachment" => true));

结果:

【问题讨论】:

标签: laravel dompdf


【解决方案1】:

首先将您的字体添加到 vendor\dompdf\dompdf\lib\fonts 例如: 巴米尼.ttf Baamini.ufm

下一步:添加一行到 dompdf_font_family_cache.dist.php 例如: '巴米尼' => 大批( '粗体' => $distFontDir 。 'Baamini-Bold', 'bold_italic' => $distFontDir 。 'Baamini-BoldItalic', '斜体' => $distFontDir 。 '巴米尼斜体', '正常' => $distFontDir 。 '巴米尼' )

现在您可以在 PDF 中使用您的字体

【讨论】:

  • 虽然这行得通,但它比它需要的更复杂。您实际上只需要使用@font-face 规则引用样式表中的字体。详情请参阅Unicode How-to
猜你喜欢
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 1970-01-01
  • 2021-02-04
  • 2021-09-24
  • 1970-01-01
  • 2017-08-29
  • 2019-06-03
相关资源
最近更新 更多