Search code examples
phptcpdfright-to-leftleft-to-right

mixing rtl with ltr in tcpdf


I'm using tcpdf to create pdf files in my webapp.

I'm using the writeHtml() function of tcpdf and trying to mix some hebrew with english,

when trying to combine both of the languages in the same line, the output comes out in the wrong direction.

for example - this is a piece of my code:

    $pdf = new TCPDF ( PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false );
    $pdf->SetDisplayMode ( "default", "OneColumn" );
    $pdf->setRTL ( false );
    $pdf->SetFont ( 'freeserif', '', 10, '' );


    $html = '<body  style="text-align: center">';
    $html .= "<p> some words in english ואחכ כמה מילים בעברית </p>";
    $html .= "<p> כמה מילים כתובות בעברית and then some words in english</p>";
    $html .= '</body>';
    $pdf->AddPage ();

    $pdf->writeHTML ( $comments_table, true, false, true, false, 'R' );
    $pdf->Output ( $path, 'F' );

the expected output will be:

some words in english ואחכ כמה מילים בעברית

כמה מילים כתובות בעברית and then some words in english.

but the words in the second language in every language come in the oppsite order my output is:

some words in english בעברית מילים כמה ואחכ

כמה מילים כתובות בעברית english in words some then and

as you can see - in the first line the english is ok - and the hebrew not, in the second line the hebrew is ok and the english isnt


Solution

  • I switched from tcpdf to mpdf which has a built in support for Bidirectional languages