Which unicode font supports all Indian fonts in mPDF library? - php

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?

Related

arabic fonts in Laravel pdf file issue

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

Mpdf - how to disable a fallback font when font-family is not available

I have a mPDF instance, in which I override the font directory and fontdata with an empty array .
What I want to achieve is that when I add HTML, which has a font-family that is not configured within my font arrays, an error is thrown. Now it automatically falls back on a font which is manually added.
mPDF instantiation
$config = [
'mode' => 'utf-8',
'format' => 'A4',
'author' => 'John Doe',
'creator' => 'John',
'default_font_size' => 12,
'default_font' => '',
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'P',
'fontDir' => [], // Don't use fallback font dir.
'fontdata' => [], // Don't use fallback fontdata
$mpdf = new Mpdf($config);
Manually adding Roboto
$config['fontDir'] = array_merge($config['fontDir'], ['path/to/my/custom/roboto/font']
$config['fontdata'] = array_merge(config['fontdata'], [
'roboto' => [
'R' => 'Roboto-Regular.ttf',
],
];
Desired Result
The problem which occurs to me is that when I do the following:
$mpdf->WriteHTML('<body style="font-family: Lato">Hello world!</body>');
mPDf automatically uses my manually added Roboto as fallback font. But I would love to know if there is a way in which I can let mPDF throw an error in which it states that the font Lato is not configured within its font-data.
I really hope you guys can help me out!
Kind Regards.
This currently cannot be done with mPDF – it will always select a suitable substitution font as a browser would do.
The process of selecting a substitute is described in the documentation.

mPDF: When I add font into .ttfonts folder then config them. mPDF is display strange text

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:

Wkhtmltopdf + cakepdf - Custom page size

I can't figure out how to enable custom page sizes with CakePDF and wkhtmltopdf. I have the following configuration code:
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
],
'orientation' => 'portrait',
'pageSize' => '', // this line
'download' => true
]);
I want to have 150x150mm pages. I already tried several things like passing an array [150,150] but also things like '150 150' or '150mm 150mm'. Is this even possible?
The CakePDF pageSize option maps to the page-size option of wkhtmltopdf, which takes QPrinter::PaperSize constant names, like for example A4, A5, B0, B1, Legal, Letter, etc., ie you cannot define a custom size using that option.
If you need a custom size, then you have to use the wkhtmltopdf specific page-width and page-height options, which both take millimeter values by default.
Quote from the wkhtmltopdf docs:
Page sizes:
The default page size of the rendered document is A4, but using this
--page-size option this can be changed to almost anything else, such as: A3,
Letter and Legal. For a full list of supported pages sizes please see
http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum.
For a more fine grained control over the page size the --page-height and
--page-width options may be used
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
'options' => [
'page-width' => 150,
'page-height' => 150
]
],
'orientation' => 'portrait',
'download' => true
]);
See also
wkhtmltopdf docs
Qt Documentation > QtGui > QPrinter > enum QPrinter::PaperSize

mPDF Open Sans font cannot render some german letters

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.

Categories