Reputation: 91
I'm using Laravel 5.5 with DOMPDF its work fine for English but not working for Unicode it's always output ????
symbol to me
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class PdfController extends Controller
{
public function export(){
$data['title']="Print Report";
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');
}
}
Blade
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
@font-face {
font-family: khmer;
font-style: normal;
font-weight: 400;
src: url({{asset('fonts/khmer.ttf')}}) format('true-type');
}
</style>
</head>
<body>
កម្ពុជាក្រោម
</body>
</html>
Result ?????????
Upvotes: 9
Views: 13413
Reputation: 79
you just need to add font-family: DejaVu Sans; in your body or also you can set the font family to any specific div in which you are going to display the Unicode Characters.
For body:
body{font-family: DejaVu Sans;}
And for a specific div:
<div style="font-family: DejaVu Sans;"> --- </div>
Hope this would help.
Upvotes: 6
Reputation: 1242
@Plan-B
i use this package it works the same way as this Dompdf-Laravel
library (Dompdf-Laravel
library works great for other languages but not Khmer font).
composer require niklasravnsborg/laravel-pdf
php artisan vendor:publish
select the library from the command prompt. You'll get the pdf.php
in config
directoryconfig/pdf.php
choose resources/fonts
directory
And here is my setup in the pdf.php
// some code here...
'font_path' => base_path('resources/fonts/'),
'font_data' => [
"khmerosmoul" => [/* Khmer */
'R' => "KhmerOSmuol.ttf",
'useOTL' => 0xFF,
],
"khmerosmoullight" => [/* Khmer */
'R' => "KhmerOSmuollight.ttf",
'useOTL' => 0xFF,
],
"khmerosbokor" => [/* Khmer */
'R' => "KhmerOSBokor.ttf",
'useOTL' => 0xFF,
],
"khmerosmoulpali" => [/* Khmer */
'R' => "KhmerOSmuolpali.ttf",
'useOTL' => 0xFF,
'useKashida' => 75
]
// ...add as many as you want.
]
Note: you might got trouble with the pdf html structure. Copy its template example form the repo and redesign it as you like. https://github.com/niklasravnsborg/laravel-pdf/blob/master/tests/views/exposify-expose.html
Upvotes: 5
Reputation: 2505
It's because your server doesn't support your font, you need to Install a font for your server which supports your Unicode font.
To Generate A PDF, the package is using system font.
Upvotes: 0
Reputation: 26
I was trying to solve similar problem in my application what I've done is I've transformed view with mb_convert_encoding function.
In your case I would to sth like that:
$data['title']="Print Report";
$pdf = mb_convert_encoding(\View::make('pdf.invoice', $data), 'HTML-ENTITIES', 'UTF-8'));
return PDF::loadHtml($pdf)->download('invoice.pdf');
Also be careful with font settings. Your needs to support UTF-8 charset.
Upvotes: 0