Hindi is not displaying properly in TCPDF

Discussion in 'PHP' started by FutureKing, Jul 8, 2017.

  1. #1
    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:
    [​IMG]


    <?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
     
    FutureKing, Jul 8, 2017 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    I found it pretty hard working with tcpdf with non latine characters. I would recommend you use mpdf instead:

    https://github.com/mpdf/mpdf

    Most functions are pretty much the same.
     
    ThePHPMaster, Jul 8, 2017 IP