When I use iconv
to convert encoding from UTF-8
to windows-1255
, all the Hebrew letters show up correctly, except for ק
, which shows up as the division symbol: ÷
:
$pdf->AddFont('Arial', '', 'arial.php');
$pdf->setFont('Arial', '', 15);
$value = iconv('UTF-8', 'windows-1255', 'ק');
$pdf->Write(1, $value);
I use a PHP package to create PDF files. So it shows up as ÷
in the PDF file, but when I copy that sign from the PDF file to Google search for example, it shows up as ק
again.
How can I fix that and show it as ק
in the PDF file as well?
I even followed the tutorial on how to create fonts with the correct encoding on the fdpf website (To create the font.z
and font.php
files)
Update: I noticed that for the mapping file for the cp1255, The line that maps to the Hebrew letter ק
is the same line that has the extended ASCII code for the division sign:
from cp1255.map
:
!F7 U+05E7 afii57687
also, here is an image of the error:
I reproduced your error and i got the same error and the reason is use of incorrect font family and encoding. Please find the solution of the issue below
On further discussion and debugging it was discovered that the MakeFont script in the old version i.e. version prior to FPDF 1.85 is buggy and throws errors, yet the files are created so it's hard to notice.
Hence If anyone is using FPDF for hebrew before version 1.85 either update you MakeFont script or use version FPDF 1.85 or later for generating .php and .z files for fonts.
step - 1 using makefont function in pdf create the font file using "font-family.ttf" of your choice. It will create 2 files font-family-name.php and font-family-name.z .... Place both the files in fonts folder in fpdf directory.
Please note you have to use encoding cp1255 for hebrew.
MakeFont('Noto_Sans_Hebrew/noto-sans-hebrew.ttf','cp1255',);
Alternatively you can create it online as well here -> makefont - fpdf
step -2 to use it you will need to addfont and setfont for the document. Please have a look at the code below.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require('fpdf/fpdf.php');
//for hebrew encoding is cp12555.
$str = 'ק מה שלומך';
$string =iconv('UTF-8', 'cp1255', $str);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->AddFont('noto-sans-hebrew','','noto-sans-hebrew.php');
$pdf->SetFont('noto-sans-hebrew','',16);
$pdf->Cell(40,10,$string);
$pdf->Output();
?>
GENERATED PDF IMAGE :
I do not understand hebrew. But please do let me know in for issues in comment.