0

I use FPDI library for php and try to add text into pdf file. It's work but when i change the text to Hebrew i got

×•× ̈×– הצלח×a×TM להוס×TM×£ × ̃×§×¡× ̃

This is my code:

<?php
use setasign\Fpdi\Fpdi;
use \setasign\Fpdi\PdfParser\StreamReader;
require_once('fpdf/fpdf.php');
require_once('fpdi/src/autoload.php');

$rawPostBody = file_get_contents('php://input');
$signatures = (array)json_decode($rawPostBody);

$fileURL = $signatures['filURL'];
$signaturesData = $signatures['signatures'];

// Initial Fpdi
$pdf = new Fpdi();
// Load external pdf file with StreamReader (We Use StreamReader Only for External file)
$fileContent = file_get_contents($fileURL,'rb');
$pdf->setSourceFile(StreamReader::createByString($fileContent));
// Get number of pages.
$pageCount = $pdf->setSourceFile(StreamReader::createByString($fileContent));
// Illiterate and create pdf pages.
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
    $tplId = $pdf->importPage($pageNumber);
    $s = $pdf->getTemplatesize($tplId);
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial','B',10);
    $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L', array($s['w'], $s['h'])); // This gets it the right dimensions
    $pdf->useTemplate($tplId, null, null, null, null, true); 
    foreach ($signaturesData as $signa) {
        if($signa->page == $pageNumber) {
            $pdf->SetXY(number_format($signa->positionX), number_format($signa->positionY * 0.264583));
            $pdf->Write(0, "שלום שלום");
        }
    }
}
$pdf->Output('pdf-with-value.pdf', 'D');   

I read some post with a similar problem but I couldn't figure out what exactly I needed to do. Thanks

Baruch Mashasha
  • 951
  • 1
  • 11
  • 29
  • 1
    You need to find a font that supports Hebrew and use it by using the fPDF function `AddFont`. The Arial font will not work. See the [landing page for fPDF](http://www.fpdf.org/) for more information on UTF-8 support. – Dave Jun 28 '20 at 19:08

1 Answers1

1

I found solution, first I download hebrew font then i put the files in font folder then:

$pdf->AddFont('Rubik-Light', '', 'Rubik-Light.php');
$pdf->SetFont('Rubik-Light', '', 15);
$value = iconv('UTF-8', 'windows-1255', html_entity_decode('עובד פיקס'));
$value = strrev($value);
$pdf->Write(0, $value);
Baruch Mashasha
  • 951
  • 1
  • 11
  • 29