Adding a new font to dompdf

To add a new Arvo font to DOMPdf, I updated the dompdf_font_family_cache.dist file and added the following code -

'arvo' => 
array (
  'normal' => DOMPDF_FONT_DIR . 'Arvo-Regular',
  'bold' => DOMPDF_FONT_DIR . 'Arvo-Bold',
  'italic' => DOMPDF_FONT_DIR . 'Arvo-Italic',
  'bold_italic' => DOMPDF_FONT_DIR . 'Arvo-BoldItalic',
),

I included the font files in the lib / fonts directory I added the stylesheet in html -

font-family: arvo;

But the new font is not added to the pdf result. Please help me solve this problem.

+5
source share
3 answers

Instead of manually modifying dompdf_font_family_cache you should use load_font.php or (in dompdf 0.6.0 beta 3) the web installer located at www / fonts.php.

+3
source

For windows with WAMP / XAMPP, etc.

  • Windows Command Prompt (Win + R-> cmd)
  • Go to C: \ wamp \ www \ dompdf
  • Copy the desired font to this folder
  • Type (example)

C:\wamp\www\bin\php\php5.4.3\php.exe load_font_php consola.ttf

+1

:

  1. load_font.php : https://github.com/dompdf/utils/blob/master/load_font.php

    1.1. .

    1.2. : php load_font.php FONTNAME FONTPATH/fonts/EXAMPLEFONT.ttf

  2. Locate and open the dompdf_font_family_cache.php file and update your file as follows (for example):

    'poppins' => 
    array(
    
    'normal' => $rootDir . '\lib\fonts\Poppins-Light_0',
    
    ),
    
  3. Go to your PDF and use your font.

These few steps can solve the problem. :)

0
source

All Articles