Hindi is not displaying properly in TCPDF

I am trying to generate PDF using TCPDF with Hindi Unicode characters. I tried Mangal, Noto Sans, Arial Unicode fonts but all give the same output. If there is a "Matra" or "Half character" then it does not display properly.

See this output:

在这里输入图像描述

<?php
error_reporting(E_ALL);
ini_set("display_errors", "On");

require_once 'vendor/autoload.php';

$hindi_str = "राष्ट्रपति प्रणव मुखर्जी। ";
$hindi_str2 = "देश हमें देता है सब कुछ";
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

//$fontname_kannada = TCPDF_FONTS::addTTFfont('NotoSansKannada-Regular.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi1 = TCPDF_FONTS::addTTFfont('NotoSansDevanagari-Regular.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi2 = TCPDF_FONTS::addTTFfont('mangal.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi3 = TCPDF_FONTS::addTTFfont("ARIALUNI.TTF", 'TrueTypeUnicode', '', 96);
// use the font

$pdf->AddPage();

$pdf->SetFont($fontname_hindi3, '', 14, '', false);
$pdf->writeHTML("<h1>Hindi $hindi_str $hindi_str2</h1>",true, false, true, false, '');
$pdf->Ln();

$pdf->writeHTML("<h1>Kannada ಖುತುಬ್ ಮಿನಾರ್ ಸಮೀಪವಿರುವ ಪ್ರಸಿದ್ಧ ಕಬ್ಬಿಣದ ಕಂಬ ಯಾರಿಗೆ ಸೇರಿದೆ</h1>",true, false, true, false, '');

// output the HTML content
 // ---------------------------------------------------------

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

Please help.


I know it's a little late, but I had the same problem for nepali (which also uses devanagari). I solved it like this:

// SOME FONTS DOES NOT SUPPORT DEVANAGARI, BUT FREESANS DOES
$pdf->SetFont('freesans', '', 10);

// MAKE ARRAY WITH UTF LANGUAGE IDENTIFIER
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'ltr';
$lg['a_meta_language'] = 'np'; // I think you can change this to HI or IN for hindi
$lg['w_page'] = 'page';

// CHANGE SETTINGS IN TCPDF
$pdf->setLanguageArray($lg);

// MAKE SURE TO USE WriteHTML() function
$pdf->WriteHTML($yourhtml, true, 0, true, 0);
链接地址: http://www.djcxy.com/p/88684.html

上一篇: DateTimeProperty在Google App Engine中将错误设置为日期时间

下一篇: 印地文在TCPDF中不能正确显示