html2pdf not converting arabic fully and RTL is a bit messed up

4k views Asked by At

I'm using html2pdf and passing $this->renderpartial('view',array(..),true) to the $content.

Here's the code:

$content = $this->renderpartial('view',array(..),true);     
$html2pdf = new HTML2PDF('P','A4','en');
$html2pdf->pdf->SetDisplayMode('real');
$html2pdf->WriteHTML($content);
$html2pdf->Output('/var/www/myapp/images/example.pdf','F');

The view declares an otf font.. which I have succesfully imported into tcpdf using an online-converter.

But the output of the pdf has some arabic, but some of the letters and weirdly english letters into squares. What's worse is that even though in my html there's the directive of RTL .. some parts of the document are still in LTR.

I have the output html with me if you need to see it.. without the html2pdf bit.. straight out from the $this->renderpartial. If you need it I'll paste it or attach as an image.

3

There are 3 answers

0
omar-ali On

Ok, so there is no problem. It's just that the font I used didn't get converted to the desired tcpdf format fully. Some characters are missing, including the english character-set.

I tried with another arabic included font and things worked fine.

This is important: html2pdf does support utf-8 out of the box when used with the tcpdf library.

0
Kal On

html2pdf does support arabic I'm using it. You ave to specify the font in the page tag and wrap the rest of your HTML code within the tag.

<page backtop="10mm" backbottom="20mm" backleft="20mm" backright="20mm" style="font-family: dejavusans">

#rest of HTML code here

</page>

0
hamza khamlichi On

Add this method, it will solve the Arabic problem in the PDF.

$html2pdf->setDefaultFont('aealarabiya');