1 year ago

#382599

test-img

Kango

dompdf not generating .ufm and dompdf_font-family_cache.php file

I am trying to use custom font in dompdf while generating pdf file. As i found that custom font works only after generating .ufm and cache file.

Drupal php file

public function GeneratePdf() {
  $dompdf = new Dompdf();
  $fontDirectory = $host.'/'.$themepath  . '/fonts';
  $options->setChroot($fontDirectory);
  $dompdf->setOptions($options);
  ob_end_clean();
  $dompdf->getFontMetrics()->registerFont(
    ['family' => 'montserrat', 'style' => 'normal', 'weight' => 'normal'],
    $fontDirectory  . '/Montserrat-Regular.ttf'
  );
  $dompdf->loadHtml($html);
  $dompdf->render();
  ob_end_clean();
}

Pdf generation HTML .twig file.

<html>
  <head>
    <style type="text/css">
      @page {
        size: auto;
        margin: 0;
        padding: 0;
      }      
     @font-face {
        font-family: montserrat;
        src: url($themepath ~'/fonts/Montserrat-Regular.ttf') format('truetype'); font-style: normal;
      }
    </style>
  </head>
  <body style="margin:0; padding:0;">   
    <span style="font-family:'montserrat';color:#417bac; font-size:18px">PDF font testing</span>
  </body>
</html>

Issue is after registering font through php function required files i.e .ufm and dompdf_font-family_cache.php not created in dompdf folder vendor\dompdf\dompdf\lib\fonts

php

pdf

pdf-generation

dompdf

laravel-dompdf

0 Answers

Your Answer

Accepted video resources