Search code examples
fontsadditionfpdfglyphicons

How can I use the font "Glyphicons" with the FPDF library?


I'm trying to use the "Glyphicons" (We bought it for 59$ to have the complete font with 610 icons and font quality not images) with the FPDF library.

Here is what I've done :

  • Create the required files for the fond with help of MakeFont
  • I get dozen of warnings saying that some usual characters are missing (it's normal, I don't want them but only pics defined by Glyphicons) :
    Warning: Character underscore is missing
    Warning: Character grave is missing
    Warning: Character a is missing
    Warning: Character b is missing
    ....
  • glyphicons.php + glyphicons.z generated
  • store the PHP and the Z files in the ./font path defined by : define('FPDF_FONTPATH', 'font/');
  • $pdf = new myPDF(); $pdf->AddFont("glyphicons"); (same as $pdf->AddFont("glyphicons", "", "glyphicons.php");)
  • Declare the font : $pdf->SetFont("GLYPHICONS", '', 10);
  • Write with this font : $pdf->Cell(0, 0, ''); (the character to write is a representation of a check icon)

However, instead of beautiful pics I got a rectangle (it means to me that it can't find the related characters within the font or the font is not available).

How can I use the Glyphicons with FPDF? Is it possible?

Thanks for your help or any feedback based on usage.


Solution

  • I should have answered to my post here. Here we are.

    For anyone coming to this post and having the same problem : Use the tFPDF add-on of FPDF: fpdf.org/~~V/en/script/script92.php.

    Important: With the current version of tFPDF, the calling PHP code seems to be strictly on the same directory as the TFPDF.php file is.

    Otherwise, the TTF path (starting from the path of TFPDF.php) can't be found getting the message:

    Can't open file font/unifont/glyphicons.ttf

    In my case I've overriden the AddFont method to specify a parameter of the rootPath and use it as prefix of the two usages of $this->_getfontpath().'unifont/'