skip to Main Content

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:

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    In my case, I used the correct fonts that are supported (Hebrew fonts), yet I had the error.

    Then I found out that the MakeFont script in the old version I had is buggy and throws errors, yet the files are created so it's hard to notice.

    So when I used the most updated MakeFont script, it fixed it


  2. 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


    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 :

    enter image description here


    **Useful links:**


    I do not understand hebrew. But please do let me know in for issues in comment.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search