0

I´m trying to generate a PDF file that contains Urdu text. I have tried several fonts like: Jameel Noori Nastaleeq, Alvi Nastaleeq, Arial Unicode, etc. But some characters do not show properly. When I copy the text from the PDF and paste it to another program like Notepad the text is showed correctly. I´m using this code to convert the .ttf file to TCPDF format.

 require_once('TCPDF/tcpdf.php');
 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
 $fontname = TCPDF_FONTS::addTTFfont('includes/Fonts/JameelNooriNastaleeqRegular.ttf', 'TrueTypeUnicode', '', 32);"" 

That code created three files: jameelnoorinastaleeq.php, jameelnoorinastaleeq.z, jameelnoorinastaleeq.ctg.z.

Then in the PHP page this is my code:

require('TCPDF/tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';

// set some language-dependent strings (optional)
$pdf->setLanguageArray($lg);

// ---------------------------------------------------------

// set font
$pdf->SetFont('jameelnoorinastaleeq','',12);


// add a page
$pdf->AddPage();

// Urdu  content
$htmlurdu = '<span color="#660000">Urdu example:</span><br />احساسات: اکساہٹ(جوش۔تحریک)؛اعصابی؛ 
<br />احساسات: اُوپر تک کھدائی کا؛"سوراخ کرنا(نقب لگانا)بل کھودنےیا بنانے کا۔؛جڑ سے اکھاڑنے۔کھود کر نکالنےکا""احساس؛"<br />احساسات: اکڑن(سختی)؛اعضاء(بازو اور ٹانگوں)کے جوڑوں کا؛(بے ڈھنگے پن(اناڑی پن)کا؛)
<br />احساسات: اینٹھن(مروڑ۔کھچاؤ)؛بیرونی(خارجی)طورپر؛';
$pdf->WriteHTML($htmlurdu, true, 0, true, 0);
//Close and output PDF document
$pdf->Output('testUrdu.pdf', 'I'); 

The Urdu Text is showed like this:

???????: ??????(?????????)????????

I have tried using an external website to convert the JameelNooriNastaleeq.ttf file to TCPDF format. I used this site http://fonts.palettize.me/ then copied the generated files to TCPDF/fonts directory but it didn´t work. Urdu text still not showing properly.

I tried the solution posted here: Urdu supported PDF library compatible with php. But there are some Urdu characters that readability is poor with font ARIAL UNICODE MS. I tried to do the same with font Jameel Noori Nastaleeq, but didn´t work. The PDF shows many spaces and very few characters, when I copy the text to another editor it is showed properly.

I have spent several hours trying to fix this problem. When showing English characters there isn´t any problem, but Urdu is not working. Sometimes it displayed "?" other times showed spaces.

Please help me!

  • Does this answer your question? [Urdu supported PDF library compatible with php](https://stackoverflow.com/questions/30207953/urdu-supported-pdf-library-compatible-with-php) – NcXNaV Jul 27 '21 at 15:14
  • The OP found the answer himself, not sure if you've tried his font/solution. – NcXNaV Jul 27 '21 at 15:20
  • I tried the solution posted but the font Arial Unicode MS is not a good option for Urdu, the readability is poor for some characters. I tried doing the same for font Jameel Noori Nataleeq but didn´t work, the Urdu text shows many spaces and not the correct characters. – Claudia Sanchez Jul 27 '21 at 20:10

0 Answers0