14

i have created below code for displaying hindi text using arial unicode font in tcpdf

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


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

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

$pdf->addTTFfont('fonts/ARIALUNI.TTF', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('arialuni', '', 10,'false');

$txt = 'hindi text with arial unicode समृध्दि';

$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);

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

//Close and output PDF document
$pdf->Output('example_038.pdf', 'I');

but it is not getting displayed properly

But in php it showing correct text.

Please tell me if there is anything wrong.

NeonGlow
  • 1,659
  • 4
  • 18
  • 36
suhas pandit
  • 273
  • 2
  • 16
  • so i don't understand. if code works.. where is the problem??? – StasGrin Nov 23 '12 at 07:59
  • You should add that it is being *displayed* **differently**. – Prasanth Nov 23 '12 at 10:39
  • i want to print समृध्दि t this hindi text but it not showing exactly same in pdf. this is the problem – suhas pandit Nov 23 '12 at 10:41
  • 1
    In my PDF reader I can find this word in text using search with "समृध्दि". Looks like everything is ok – Egor Sazanovich Nov 23 '12 at 11:01
  • it seems tcpdf is not recognizing utf characters properly. समृध्दि is a bit complex word try using simple utf8 words. or try different combination on http://google.com/transliterate/indic try writing in hindi, marathi and other devnagri fonts, something may work – Pankaj Khairnar Nov 23 '12 at 13:11
  • i have got solution, now i used MPDF for this, its working fine. example link -: http://mpdf1.com/examples/example_utf8.pdf – suhas pandit Nov 26 '12 at 05:33
  • You should let TCPDF know :) – Prof Dec 02 '12 at 22:14

4 Answers4

2

Try mPDF as an alternative. It is very good and easy to use. Here is an example of how it displays Hindi

Amr
  • 4,809
  • 6
  • 46
  • 60
0

I would try mpdf1.com I have tried it before, and it worked with hindi

LukasFT
  • 164
  • 2
  • 10
-1

Something could be wrong with the font.

Try replacing the following lines and trying another font:

$pdf->addTTFfont('fonts/ARIALUNI.TTF', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('arialuni', '', 10,'false');
safrazik
  • 1,517
  • 10
  • 14
-1

Try this, it works.

$mpdf->SetAutoFont();