简体   繁体   中英

Converting html 2 pdf (php) using hebrew returns “???”

I have a using html2pdf library from this link http://html2pdf.fr/en/ and I am trying to get a simple html code into html, the problem is that my text is Hebrew langue and for some reason instead of the text I am getting something like this "???".

The same Html code in the browser that set on UTF-8 is working fine !

This is my php code:

    $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8');
    $html2pdf->setDefaultFont('arial'); //add this line
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($output, false);
    $html2pdf->Output('names.pdf');

I tried to use this

    $html2pdf->setDefaultFont('arialunicid0');

And it did help most of the character showed up correctly but not of them, if anyone have any ideas how can I fix this I will be very grateful I really need this !

The Html2pdf simply convert an HTML content to PDF. so i would recommend you to validate the HTML that you are passing to html2pdf is correct.

also instead of

$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8');

try using

$html2pdf = new HTML2PDF('P', 'A4', 'he', true, 'UTF-8');

If that too does not work then this means that you are using incorrect version of html2pdf in this case i shall recommend you to use this fork

https://github.com/iafan/html2pdf/blob/master/_tcpdf_5.9.206/config/lang/heb.php

otherwise use some other library like FPDF

尝试使用其他字体:

$html2pdf->setDefaultFont('dejavusans');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM