Reputation: 745
how to set mpdf HTML contains invalid UTF-8 character(s) when you create pdf on your appliactions
Upvotes: 14
Views: 43914
Reputation: 867
I got this error when I send NULL
to ->multicell()
. Sending ""
fixed it.
Upvotes: 0
Reputation: 3477
This works for me:
Use
autoScriptToLang = true;
autoLangToFont = true;
include("mpdf-6.0.0/mpdf.php");
$mpdf = new mPDF('c', 'A4', '', '', 0, 0, 0, 0, 0, 0);
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($html);
$mpdf->Output('SavePDF.pdf', 'D');
Upvotes: 2
Reputation: 719
I'm 99% sure that problem is because you did some manipulations with the text using unicode-unsafe functions. Use mb_strpos()/mb_substr()
instead of strpos()/substr()
, and add "/u
" modifier to all your conversions with prog_replace()
.
Of course, the problem can be fixed by allowing "charset conversion" as already suggested before. But much better to know that your text already correct and meets the compliance of UTF-8.
Upvotes: 0
Reputation: 11
After hours of hair-pulling, this worked wonders for me :)
(In my case बोटोक्स was showing as ??????)
$mpdf->SetAutoFont();
$mpdf = new mPDF('utf-8','', 0, '', 15, 15, 16, 16, 9, 9, 'L');
$mpdf->SetAutoFont();
//~ Nothing of below worked :(
//~ $mpdf->useLang = true;
//~ $mpdf->autoScriptToLang = true;
//~ $mpdf->autoLangToFont = true;
//~ $pdf_html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($html);
//~ $mpdf->DeletePages(2);
$filename = date('ymdhis').".pdf";
$mpdf->Output($filename,'D');
My PDF included a mix of English and Hindi words like
"3 units of बोटोक्स Priced @ $10.00/unit".
Upvotes: 1
Reputation: 997
The below two lines will do the trick
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'iso-8859-4';
Add the above two lines after creating the object , this will look like
$mpdf=new mPDF();
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'iso-8859-4';
Upvotes: 4
Reputation: 116
With mpdf it is no point in conversions and encoding as these most likely will lose your chars and you would get only "?" or other unrecognisable chars (but will yield output)
Try using these before any input being send to mpdf:
$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='UTF-8';
Upvotes: 7
Reputation: 411
Try this
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
before calling: "$mpdf->WriteHTML($html);"
It's seems senseless, but it works for me.
Upvotes: 41
Reputation: 745
Use utf8_encode() function. Eg : $html = '
Name of Originator
Originator Address
Originator Phone Number
Originator Email
Borrower
Property Address
Date of GFE
Â
'; $html = utf8_encode($html1);
Upvotes: 3