Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to print a greek character in pdf using php script & fpdf

while trying to print a greek character 'φ' I get the following character printed on the pdf 'φ'

like image 521
Sai Nikhil Avatar asked Jan 17 '23 15:01

Sai Nikhil


1 Answers

I will leave this here for the next ones.

FPDF has its own guide for importing new fonts for specific encodings. The steps are:

  1. Go to http://www.fpdf.org/makefont/ and upload the .ttf or .otf file of your font (make sure font is supporting greek characters like Courier New).
  2. For the encoding option select ISO-8859-7 (preferably) or cp1253 according to the guide.
  3. Download the .php and .z files that are created and store them on fpdf/font folder (like the default fonts) of the fpdf package.
  4. Import the font at runtime to the pdf file $pdf->AddFont('Courier New', '', 'Courier New.php');
  5. And use it $pdf->SetFont('Courier New', '', 20);
  6. You have to convert the string you will print to ISO-8859-7 encoding. This is done with $text = iconv('UTF-8', 'ISO-8859-7', $text);
  7. Then you can finally print the string $pdf->Write(20,$text);
like image 79
Theofanis Avatar answered Jan 25 '23 14:01

Theofanis