Php – How to generate PDF with Bangla (Unicode) font using fpdf

fpdfpdfPHPunicode

I am working on a PHP based system in which i need to generate PDF files for reporting purpose. I am using fpdf library for this.

Now there can be Bangla characters in those PDF file. I tried so many ways and also tried Adding new fonts and encoding support fpdf but none is working for me.

Trying to solve this problem for last 1 day but didnt succeeded. If anybody have any solution or atleast know how to do this.

Edit:

I used Solaiman-Lipi font for this. I generated solaiman-lipi.php & solaiman-lipi.z file accordingly and then used below code to generate the PDF:

require('fpdf.php');

$pdf = new FPDF();
$pdf->AddFont('SolaimanLipi','','solaiman-lipi.php');
$pdf->AddPage();
$pdf->SetFont('SolaimanLipi','',35);
$str = iconv('UTF-8', 'windows-1252', '??? ??? ????');
$pdf->Write(10,$str);
$pdf->Output();

Edit:

Optionally i am attaching an image:

Unicode problem while generating PDF

Edit:

Added what the output should look like in PDF. This is Bangla Text.

enter image description here

Best Answer

You could use mPDF instead of fpdf as library and use nikosh as bangla font. First, you have to copy nikosh.ttf font file on /ttfonts folder of mpdf library. Then, change config_fonts.php file. Add

"nikosh" => array(
    'R' => "Nikosh.ttf",
    'useOTL' => 0xFF,       
    ), 

inside the fontdata array. As Bangla has similarity with Indic language so I added Bangla font (Nikosh) information after Indic fonts.

For details you could see the following articles:

http://jobnstudy.blogspot.com/2016/10/how-to-write-bengali-bangla-unicode-pdf.html

Related Topic