2
votes

I have this block of code to use MPDF PHP library to convert a HTML document to PDF document, HTML document has both LTR and RTL languages:

    $mpdf = new mPDF;
    $content = '<div lang="he" style="direction: rtl;">רוחב: <span lang="en" style="direction: ltr; display: inline-block">483 mm (19")</span></div>';
    $mpdf->autoLangToFont = true;
    $mpdf->WriteHTML($content);
    $mpdf->Output();

The HTML version of $content displays correctly:

enter image description here

But in the PDF version, I get this

enter image description here

I have tried to apply many CSS styles but couldn't find any way to solve this. Do you have any solution? Thanks!

P/S: I don't speak Hebrew or any RTL language.

1
Try to set rtl for parent div only - $content = '<div lang="he" style="direction: rtl;">רוחב: <span lang="en">483 mm (19")</span></div>';Armen
Thank you @Armen, I already tried that but the result was the same.Hung Tran
I just tested your code and it works for me. What mPDF version are you using?simon
@simon it is mPDF 6.0 (20/12/2014)Hung Tran

1 Answers

2
votes

Your code is working fine in mPDF 5.7.4.

For mPDF 6.0 you need to use <bdo> element instead of the css property direction:

$content = '<div dir="rtl">רוחב: <bdo dir="ltr">483 mm (19")</bdo></div>';

For more information about mPDF 6.0 see this reference.