Search code examples
phpfpdf

FPDF - Adding a google webfont


I'm using FPDF to generate a pdf with PHP and I want to use the same font than my website, Lato. But on my site, I use a google webfont link :

http://fonts.googleapis.com/css?family=Lato%3A300%2C400%2C700%2C900%2C300italic%2C400italic%2C700italic

So I don't have the files and I want to know if there's a way to use this font in my pdf ?

Thanks


Solution

  • What you can do is download the font and install it in your system, and define the font path,

    define('FPDF_FONTPATH','/home/www/font');
    

    and then set the font accordingly - doc link

    // Times regular 12
    $pdf->SetFont('Times');
    // Arial bold 14
    $pdf->SetFont('Arial','B',14);
    // Removes bold
    $pdf->SetFont('');
    // Times bold, italic and underlined 14
    $pdf->SetFont('Times','BIU');
    

    FPDF accepts only .ttf, .otf or .pfb file type.

    A quick googling will get you the links for Lato font,

    Maybe you will have to check this link also (Link)