I am trying to write some Indian dialect texts in my pdf, using mPDF library. I've tried using these fonts:
'fontdata' => [
"sakalbharati" => [
'R' => "Sakal Bharati.ttf",
'useOTL' => 0xFF,
],
"mangal" => [
'R' => "Mangal.ttf",
'useOTL' => 0xFF,
],
"freesans" => [
'R' => "FreeSans.ttf",
'B' => "FreeSansBold.ttf",
'I' => "FreeSansOblique.ttf",
'BI' => "FreeSansBoldOblique.ttf",
'useOTL' => 0xFF,
],
]
Most of these fonts work only when rendering Hindi characters (there are some grammatical mistakes when rendering complex Hindi words though), but when I try to render other dialect characters such as Bengali, Assamese, etc., they render as squares in my pdf:
Please see this image
How do I fix this issue? Is there a font which will support all Indian unicode font characters?
For generating pdf files in my Laravel app, I used niklasravnsborg/laravel-pdf package that it supports arabic language, No I want add custom fonts, I followed the documentation but it's not working, the text was showin with the default font of the package (I don't know what is..)
this is config/pdf.php :
...
'font_path' => base_path('/resources/fonts/'),
'font_data' => [
'NotoKufiArabic' => [
'R' => 'NotoKufiArabic-VariableFont_wght.ttf', // regular font // I tried also NotoKufiArabic-Regular
'B' => 'NotoKufiArabic-Bold.ttf', // optional: bold font
'I' => 'NotoKufiArabic-Medium.ttf', // optional: italic font
'BI' => 'NotoKufiArabic-SemiBold.ttf' ,// optional: bold-italic font
'useOTL' => 0xFF, // required for complicated langs like Persian, Arabic and Chinese
'useKashida' => 75, // required for complicated langs like Persian, Arabic and Chinese
]
// ...add as many as you want.
]
css code in blade :
body {
font-family: "NotoKufiArabic", sans-serif;
}
and I added .ttf files in fonts directory like this
I'm currently working on making the correct version of language dependent glyphs show up in their respective PDF files... From what I understand after reading through the mPDF documentation is that all I need to do is to set the the html lang value like below and to set autoScriptToLang and autoLangToFont to true
Example html where I want the Japanese version of the characters:
<html lang="ja">
<body>
Sample language-dependent glyphs: 直今令角雇
</body>
</html>
And yet it doesn't seem to reflect on the PDF file that is generated.
Here's the settings I'm passing over to Mpdf\Mpdf
$settings = [
'autoLangToFont' => true,
'autoScriptToLang' => true,
'format' => 'A4',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 20,
'margin_header' => 0,
'margin_footer' => 5,
'tempDir' => '/tmp/',
'default_font' => 'frutiger'
];
I tried displaying the HTML I'm passing over to mPDF and it works there, so I believe my issue is that I'm missing a setting to allow mPDF to display the Japanese versions of those characters.
private function preset($name){
// Full Feature
if($name == 'full'){
return array(
'selector' => 'textarea',
'theme' => 'modern',
'plugins' => 'advlist,autolink,lists,link,image,charmap,print,preview,hr,anchor,pagebreak,
searchreplace,wordcount,visualblocks,visualchars,code,fullscreen,
insertdatetime,media,nonbreaking,save,table,contextmenu,directionality,
emoticons,template,paste,textcolor,youtube,colorpicker',
'relative_urls' => false,
'browser_spellcheck' => true,
'toolbar1' => 'insertfile, undo, redo, |, styleselect, fontselect, |, fontsizeselect, |, bold, italic, |, alignleft, aligncenter, alignright, alignjustify, |, bullist, numlist, outdent, indent',
'toolbar2' => 'link, image, media, youtube, emoticons, |, colorpicker, forecolor, backcolor, |, preview, print, code',
'language' => 'hi_IN',
'content_css' => ['http://englishcosmos.in/exam/hindifont.css'],
'font_formats' => 'Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Poppins= poppins,sans-serif;Indie Flower=indie flower, cursive;Hind= hind,sans-serif',
'image_advtab' => true,
'file_browser_callback' => 'elFinderBrowser'
);
}
Here code has option to set font dropdown, fontsize. Here all fonts from google working but Hindi font not working.
Is there any solution that I can use hindi font from google or directly.
Font I want to use here is : Kurti Dev
Try to expand it. Look at the option content_css of TinyMCE (link). Yes, U use it ( http://englishcosmos.in/exam/hindifont.css => 404 ). In that file U have to input something like :
#font-face {
font-family: "Kruti Dev";
src: url("../path_to_ttf-file/kruti.ttf");
}
body{
font-family:'Kruti Dev', Verdana;
...
}
I have this problem. I Don't know how to explain.
When I add thai font (TH sarabun) into .ttfonts folder.
and config in config_fonts.php file
follow this:
"sarabun" => array(/* Thai */
'R' => "THSarabun.ttf",
'B' => "THSarabun_Bold.ttf",
'I' => "THSarabun_Italic.ttf",
'BI' => "THSarabun_Bold_Italic.ttf",
'useOTL' => 0xFF,
),
//similar garuda font'
//"garuda" => array(/* Thai */
// 'R' => "Garuda.ttf",
// 'B' => "Garuda-Bold.ttf",
// 'I' => "Garuda-Oblique.ttf",
// 'BI' => "Garuda-BoldOblique.ttf",
// 'useOTL' => 0xFF,
// ),
Then I coding mpdf follow this (I assume my code isn't error.)
$this->pdf = new mPDF();
$html = $this->load->view('.........');
$this->pdf->writeHTML($html);
$this->pdf->Output();
Then mPDF displays the square text and text.
follow this:
The square text is wrong or bad reading
I want to remove square text or don't want to show or disappear.
How should I solve these problems?
P.S.
If I remove 'useOTL' => 0xFF is correct display.But Word wrapping is bad.
It's more than space when I used justify text. or some line is short. Some line is long.
example: