How to install mpdf HTML contains invalid UTF-8 character

how to install mpdf HTML contains invalid UTF-8 characters when creating pdf on your applications

+10
source share
8 answers

try it

$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8'); 

before the call: "$ mpdf-> WriteHTML ($ html);"

It seems pointless, but it works for me.

+22
source

With mpdf, it makes no sense to convert and encode, because they are likely to lose your characters, and you only get a "?". or other unrecognizable characters (but will give a way out)

Try using them before any input is sent to mpdf:

 $mpdf->allow_charset_conversion=true; $mpdf->charset_in='UTF-8'; 
+4
source

Use the utf8_encode () function. For example: $ html = '

Name of originator

Initiator address

Initiator Phone Number

Original Email

The borrower

Property Address

GFE Date

Γ‚

'; $ html = utf8_encode ($ html1);

+2
source

Below two lines will do the trick

 $mpdf->allow_charset_conversion = true; $mpdf->charset_in = 'iso-8859-4'; 

Add the two above lines after creating the object, it will look like

 $mpdf=new mPDF(); $mpdf->allow_charset_conversion = true; $mpdf->charset_in = 'iso-8859-4'; 
+1
source

This works for me:

 $mpdf->WriteHTML(utf8_encode($html)); 
+1
source

I got this error when I sent NULL to ->multicell() . Sending "" fixed.

old question, but maybe someone comes here from google, as I did

0
source

After hours of pulling my hair, it worked wonders for me :)

(In my case, ΰ€¬ΰ₯‹ΰ€Ÿΰ₯‹ΰ€•ΰ₯ΰ€Έ showed up 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 contained a mixture of English and Hindi words such as

"3 units ΰ€¬ΰ₯‹ΰ€Ÿΰ₯‹ΰ€•ΰ₯ΰ€Έ for $ 10.00 / unit."

0
source

I'm 99% sure that the problem is that you did some text manipulation using the unsafe Unicode functions. Use mb_strpos()/mb_substr() instead of strpos()/substr() and add the modifier " /u " to all your conversions with prog_replace() .

Of course, the problem can be solved by resolving the "encoding conversion", as previously suggested. But it’s much better to know that your text is already correct and meets the requirements of UTF-8.

0
source

Source: https://habr.com/ru/post/983023/


All Articles