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

社会主义新天地 提交于 2020-01-17 07:50:14

问题


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 !


回答1:


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




回答2:


Try using different font:

$html2pdf->setDefaultFont('dejavusans');


来源:https://stackoverflow.com/questions/27183530/converting-html-2-pdf-php-using-hebrew-returns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!