I think i found the solution of this problem. i've tried some library (dompdf, TCPDF,FPDF,mPDF) which support PHP but not all of them are work properly. I didn't find any unicode support with dompdf,
tcpdf worked but the fonts are broken. so i tried mPDF and it gave me my expected output.
i'm using this library to my laravel project. To using mPDF with laravel project you need to follow the documentation of laravel-mpdf.
link: https://github.com/niklasravnsborg/laravel-pdf
after installed the library successfully what you have to do this following steps for other language or bangla support.
first download the fonts for your supported language (i.e: for bangla i've downloaded solaimanLipi.ttf) and keep it to your fonts folder inside the resources folder. if there is no fonts folder just create it.
2.In config/pdf.php file add these codes inside of return array
'font_path' => base_path('resources/fonts/'),
'font_data' => [
'examplefont' => [
'R' => 'ExampleFont-Regular.ttf', // regular font
'B' => 'ExampleFont-Bold.ttf', // optional: bold font
'I' => 'ExampleFont-Italic.ttf', // optional: italic font
'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
'useOTL' => 0xFF,
'useKashida' => 75,
]
// ...add as many as you want.
]
examplefont is your attribute name whatever you want to use. but inside this attribute paste your font name.
Example:
'bangla' => [
'R' => 'SolaimanLipi.ttf', // regular font
'B' => 'SolaimanLipi.ttf', // optional: bold font
'I' => 'SolaimanLipi.ttf', // optional: italic font
'BI' => 'SolaimanLipi.ttf' // optional: bold-italic font
'useOTL' => 0xFF,
'useKashida' => 75,
]
now in your view file use this CSS Scripts:
<style>
body {
font-family: 'examplefont', sans-serif;
}
</style>
In Your Controller:
function generate_pdf() {
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('document.pdf');
}
Hints: pdf.document is your view file name.
Use PDF at the top in your namespace
If you follow this step correctly ,it will work 100%.
This is my output
Output
N.B: This is my first post. if i did any mistakes to write review in correct format please consider it take it lightly.
Thank You,
Mahabubul Islam Mehedi