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
Related
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?
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:
Working with Yii framework 2, I use kartik\mpdf\Pdf class to response my HTML page in PDF format to the browser. Below is my configuration.
$pdf = new kartik\mpdf\Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $htmlContent,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
'cssInline' => '.kv-heading-1{font-size:18px} .page-break{ page-break-after:always; } li { list-style:none; }',
// set mPDF properties on the fly
'options' => ['title' => 'My title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['My_header_ ' . date('d-m-Y')],
'SetFooter'=>['{PAGENO}'],
],
]);
// return the pdf output as per the destination setting
return $pdf->render();
Everything works perfectly, except when there is a variable inside my HTML page, which returns a long string, that text becomes small. How can I solve it?
mPDF resizes too large tables to fit a page. To prevent this, either add
'options' => ['shrink_tables_to_fit' => 0];
to your kartik\mpdf\Pdf constructor call OR set a custom HTML attribute
<table autosize="0">
Also see mPDF manual on tables.
I am trying to generate PDF with the german word "möchte" (the letter ö is the issue here)..
using the font that I added(Open Sans) in /ttfonts folder and set it on config_fonts.php..
"open_sans" => array(
'B' => "OpenSans-Bold.ttf",
'BI' => "OpenSans-BoldItalic.ttf",
'EB' => "OpenSans-ExtraBold.ttf",
'EBI' => "OpenSans-ExtraBoldItalic.ttf",
'I' => "OpenSans-Italic.ttf",
'L' => "OpenSans-Light.ttf",
'LI' => "OpenSans-LightItalic.ttf",
'R' => "OpenSans-Regular.ttf",
'SB' => "OpenSans-Semibold.ttf",
'SBI' => "OpenSans-SemiboldItalic.ttf",
'useOTL' => 0xFF,
'useKashida' => 75,
)
I also read https://mpdf.github.io/fonts-languages/fonts-in-mpdf-6-x.html and tried modifying config_lang2fonts.php .. I even set it everything to open_sans
$unifont = "open_sans";
return array($coreSuitable ,$unifont);
PS: The font file Open Sans I downloaded is already no subsetting.
But the output is still not like as I expected, it shows:
PHP
$mpdf = new mPDF('','A4','','open_sans' , 30 , 12 , 12 , 12 , 10 , 10);
Mark Up
#font-face{
font-family:open_sans;
src: url('mypath/mpdf60/ttfonts/OpenSans-Regular.ttf');
}
I tried using the default fonts of mPDF like dejavusans, It works perfectly. But what I need is Open Sans. Did I miss a configuration in mPDF or what? What is the problem?
The fact that you see a regular o followed by an unknown character strongly suggests the second character is a single non-spacing diaeresis, not available in the font you are using.
Checking the character sets of DejaVu Sans and Open Sans proves my hunch is right. DejaVu Sans does contain a 'COMBINING DIAERESIS' U+0308: ¨. OpenSans does not.
Use Unicode Normalization on your input text to replace the sequence o+¨ with its composite character ö U+00F6. The same goes for ä U+00E4 and ü O+00FC.