0

I want to add Baamini font in Dompdf and also i want to add header and footer in dompdf My Controller :

 $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));

Result:

result

  • You have asked two questions here, best to stick to one question per post to ensure the most accurate and helpful responses. – BrianS Jan 21 '20 at 02:42
  • For the header/footer question, try here: https://stackoverflow.com/q/7484318/264628 – BrianS Jan 21 '20 at 02:43
  • Does this answer your question? [Header in PDF page using DOMPDF in PHP](https://stackoverflow.com/questions/7484318/header-in-pdf-page-using-dompdf-in-php) – BrianS Jan 21 '20 at 02:43

1 Answers1

0

First add your font to vendor\dompdf\dompdf\lib\fonts eg: Baamini.ttf Baamini.ufm

Next : add a lines to dompdf_font_family_cache.dist.php eg: 'baamini' => array( 'bold' => $distFontDir . 'Baamini-Bold', 'bold_italic' => $distFontDir . 'Baamini-BoldItalic', 'italic' => $distFontDir . 'Baamini-Italic', 'normal' => $distFontDir . 'Baamini' )

Now you can use your font in PDF

  • Whiel this works, it's more complicated than it needs to be. You really only need to reference the font in the stylesheet using an `@font-face` rule. See the [Unicode How-to](https://github.com/dompdf/dompdf/wiki/UnicodeHowTo) for details. – BrianS Jan 21 '20 at 02:39