Arabic font displayed in reverse order in dompdf

I use dompdf to convert an html page using dompdf, but it shows Arabic text in reverse order

For example, if the text

ايبنسيالرمس

then it is displayed as

مرلايسنبيا in PDF

Any idea why?

+3
php arabic dompdf
source share
2 answers

dompdf does not currently support directivity, so RTL languages ​​will not display correctly with respect to character stream. There is a hack for displaying characters in the correct order, although this requires modification of the dompdf code.

If you want to try a modification, two steps are necessary. First, create any text that should display RTL with direction: rtl; text-align: right; direction: rtl; text-align: right; . Then, in the dompdf / include / text_renderer.cls.php file, add the following lines before each instance of $canvas->text() (or any option, for example $this->_canvas->text() ):

 if (strtolower($style->direction) == 'rtl') { preg_match_all('/./us', $text, $ar); $text = join('',array_reverse($ar[0])); } 

(You may need to change the variable name $text to match what is used in the code.)

Literature:

In addition, we saw problems when the characters do not combine, as expected, when pronouncing the words. This is a problem that we have not yet had the opportunity to investigate.

Literature:

Your best option now for full focus support is to use a mute browser, for example. PhantomJS .

+5
source share

Only the output with @BrianS answer is that from left to right the characters in the string are displayed from right to left. Here's how I solved it (in my case, the check is for Hebrew characters):

 // check if the line contains Hebrew characters from the start too // to avoid flipping dates etc. if( strtolower( $style -> direction ) == 'rtl' && preg_match( "/\p{Hebrew}/u", $text ) ): preg_match_all('/./us', $text, $ar); // reverse the whole line $text = join('',array_reverse($ar[0])); // flip english back to ltr $words = explode( ' ', $text ); foreach( $words as $i => $word ): if( !preg_match( "/\p{Hebrew}/u", $word ) ): $words[$i] = implode( '', array_reverse( str_split( $word ) ) ); endif; endforeach; $text = implode( ' ', $words ); endif; 
+1
source share

All Articles