Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Fonts for DOMPDF

I'm Using DOM PDF 0.6.0 Beta 2. I want to use custom fonts (Fonts: 'Segeo Print', 'Lucida Handwriting','Airplanes in the Night Sky') in PDF file.

I followed the guidelines to install and use fonts in my PHP Code, which is given here http://code.google.com/p/dompdf/wiki/CPDFUnicode

But I'm not able to get desire fonts in my PDF. You can find my code in this post. Please Let me know how I can resolve this issue.

<?php          require_once("dompdf_config.inc.php");     $html = "<html>                 <head>                        <meta http-equiv='Content-Type' content='text/html;charset=utf-8'>                     <style>                         *{font-size:15px;}                           div.ClJ{font: nightsky;}                        </style>                       </head>                 <body>                                <div class='ClJ'>This text is in DIV Element</div><br /><br />                 </body>           </html>";      $dompdf = new DOMPDF();         $dompdf->load_html($html);     $dompdf->render();     $pdf = $dompdf->output();     $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));  ?>     
like image 392
pinaldesai Avatar asked Sep 25 '12 10:09

pinaldesai


People also ask

How do I use font family in PDF?

Open the command line, go to the root folder of your project, and run the utility with the name of the font you are registering and the path to the TFF file eg php load_font. php SourceSansPro ./pathToYourFolder/lib/dompdf/SourceSansPro-Regular. ttf ./pathToYourFolder/lib/dompdf/SourceSansPro-Bold. ttf.


Video Answer


2 Answers

  1. go to your DOMPDF folder
  2. copy your font's as .ttf (TrueType Font) or .otf (OpenType Font) into the DOMPDF's root
  3. open your command line and run
    php load_font.php your_fonts_name ./your-normal.ttf ./your-bold.ttf ./your-bold-italic.ttf
  4. DOMPDF now created Adobe Font Metrics and copied it to lib/fonts/* - you can now use it with
    font-family: your_fonts_name;
like image 99
Ueli Avatar answered Sep 21 '22 10:09

Ueli


you can add css font :

@font-face {     font-family: new_font;     src: url('my_font.ttf'); } 

and than

div.ClJ{     font-family: new_font;  } 
like image 33
chokrijobs Avatar answered Sep 21 '22 10:09

chokrijobs