Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in Arabic text in dompdf #712

Closed
amr87 opened this issue Sep 6, 2013 · 92 comments
Closed

Problem in Arabic text in dompdf #712

amr87 opened this issue Sep 6, 2013 · 92 comments

Comments

@amr87
Copy link

amr87 commented Sep 6, 2013

I went to unicode discussion and googled it and looked for it in stackverflow

I did everything you recommended from using standard meta tag with content type and charset to loading font that supports arabic

and the result was I got arabic letters separated from each other and reversed

so plz let me know If you have really a serious issue regarding supporting arabic text ??

please refer to attached image
capture

@bsweeney
Copy link
Member

bsweeney commented Sep 6, 2013

Are you saying the characters themselves are reversed or that you were expecting RTL and got LTR? I don't read Arabic and so am unable to really make much sense of the issue just looking at the PDF. At the very least seeing a PDF with the correct display would help.

One thing you might try to see how it affects the render is to turn off font sub-setting (if enabled).

To debug the issue we would want to be able to access the actual HTML and font used.

@amr87
Copy link
Author

amr87 commented Sep 6, 2013

in Arabic the letters is tied together to form a word , its not about setting RTL or LTR because the problems in letters not words
the font I am using is Arial which is know for Arabic support

below is the code
attached image is how should the text look properly
capture

this how the code look iam sorry I try to paste code but it renders as html , I do not know to paste as a code only

ss

thank you

@bsweeney
Copy link
Member

bsweeney commented Sep 6, 2013

Can you post the HTML in non-image format for easier replication in testing?

@amr87
Copy link
Author

amr87 commented Sep 6, 2013

I am sorry I did not know how to post html code without getting it parsed in the comment
BTW: file encoding was UTF-8 also

<!DOCTYPE html>
<head>
<title>Untitled</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body  style="font-family:Arial">
<h1>مصدر بوزارة الدفاع: السيسي اعتمد قائمة اغتيالات بين صفوف مهندسي الانقلاب وانتهى من خطة اعلامية للصق التهم بالإخوان والجماعة الإسلامية وحماس .. وأنباء عن خلاف بين “السيسي” و”صدقي” حول تعديل مسار استخدام العنف</h1>
           <img src="test2.jpg"/>
<p>أكد مصدر بوزارة الدفاع لأحد المفكرين القريبين من التحالف الوطني لدعم الشرعية أن الفريق عبد الفتاح السيسي اعتمد بشكل نهائي قائمة من الاغتيالات لعدد من رموز الاحزاب ومهندسي الانقلاب العسكري الذين لم يعد لهم دور مؤثر في المرحلة الراهنة والصاق تهم الاغتيال لجماعة الإخوان المسلمين.

وأكد المصدر أن قائمة الاغتيالات تضم الشيخ علي جمعة – المفتي السابق للجمهورية – وأحد داعملي الانقلاب العسكري، كما تضم ثلاث شخصيات من جبهة الانقاذ و12 قيادة أمنية من الجيش والشرطة وأحد القساوسة من اعضاء المجلس الملي.

وكشف المصدر أن “السيسي” كان قد التقى ثلاث إعلاميين خلال الـ48 ساعة الماضية للاتفاق على خطة اعلامية في الداخل والخارج لتسويق حملة الاغتيالات والصاقها بالاخوان والعمل على تصنيف الإخوان كجماعة إرهابية في الداخل والخارج.

وأكد المصدر أن خطة السيسي تعتمد على توجيه الاتهام لعدد من قيادات الإخوان والتحالف الوطني لدعم الشرعية وعلى رأسهم الدكتور محمد بديع – المرشد العام للإخوان – والدكتور محمد البلتاجي – القيادي بالجماعة والشيخ صفوت حجازي – القيادي بالتحالف – والمهندس عاصم عبد الماجد – المتحدث باسم الجماعة الاسلامية – ، فضلًا عن عدد من قيادات حركة المقاومة الاسلامية حماس.

وفي سياق متصل ترددت أنباء حول خلافات بين الفريق أول عبد الفتاح السيسي والفريق صبحي صدقي حول استمرار مسار العنف في الشاارع ضد المتظاهرين، وكانت مصادر قد أكدت أن واشنطن والاتحاد الاوروبي كانوا قد هددوا بقطع المعونات العسكرية قبل الاعلان عنها في محاولة للضغط على قيادات الانقلاب لوقف المجازر ضد المتظاهرين السلميين.

وكانت خلافات قد ظهرت بين “السيسي” و”صدقي” حول تعديل مسار استخدام العنف لتفادي وقف المعونات العسكرية واستخدام خطط بديلة في القضاء على ملف الاسلام السياسي بدون إعلان رعاية الدولة بشكل رسمي للمخطط.</p>

</body>
</html>



@bsweeney
Copy link
Member

bsweeney commented Sep 7, 2013

No worries, markdown takes a little getting used to, but it's easy to pick up. Plus we can go in and edit issues/comments.

@amr87
Copy link
Author

amr87 commented Sep 10, 2013

any feedback regarding this problem ?

@bsweeney
Copy link
Member

Not yet. We'll need to perform additional testing on this issue before we can provide any specific feedback. This may be an issue of how the text is represented in the PDF and how it is mapped to the font glyphs. In which case we'll have to research the issue a bit more before we can work out a solution.

@amr87
Copy link
Author

amr87 commented Sep 10, 2013

ok , thank you
please keep me up to date with any solution you find :)

@rjbijl
Copy link

rjbijl commented Oct 8, 2013

@bsweeney, is this somewhat related to this old post I found? https://groups.google.com/forum/#!msg/dompdf/qfWb24ct7Ts/5_KKgc2ufqQJ

I played around with it a bit, and it sortof seems to work, but I guess it never made it into the master branch? Is this still something you would recommend?

@bsweeney
Copy link
Member

bsweeney commented Oct 8, 2013

@rjbijl I believe the RTL issue is a separate, but still valid, problem for dompdf. If you're looking for RTL support then, yes, give the advice in that discussion a try.

This issue, if I am correct, is about the visual display of "words" in the PDF. The individual characters display correctly, but when combined into a word they should be linked (similar to cursive script in English). For some reason this is not happening.

@rjbijl
Copy link

rjbijl commented Oct 9, 2013

ok, my bad, I guess I got confused by the images. I'll try and see if I can come up with something decent regarding the RTL rendering, I do think that would be a real improvement for dompdf

@sajjadrad
Copy link

Thanks for this amazing library.

TCPDF Library handled this problem for persian and arabic characters.I think you can take a look about it.

@eyal7773
Copy link

Just small modification, hope you will enter it to the main :

this code has to be insered into file dompdf/include/text_renderer.cls.php, before "$this->_canvas->text".

and now the Hebrew/Ara bic is in the RTL direction.
But if there are numbers in the string - so it will be shown in the LTR direction.

if (strtolower($style->direction) == 'rtl' && !mb_detect_encoding($text, array("ASCII"))) {
  preg_match_all('/./us', $text, $ar);
  $text = join('',array_reverse($ar[0]));
  // if there are numbers in the string
  // so the next line reverse the number back
  // treat also numbers with dot (decimal) and email
  $text = preg_replace_callback('/\d+-\d+|\d+|\d+\.\d+|\S+@\S+/', function (array $m) { return strrev($m[0]); }, $text);
}

(this is improved solution from http://stackoverflow.com/questions/21201257/arabic-fonts-display-in-reverse-order-in-dompdf )

PLEASE BE AWARE that mb_detect_encoding is not working properly, maybee it good to use only the rtl condition.

@t3rep-com
Copy link

Hi , the best solution to support and fix arabic characters in dompdf Library you should integrate
ar-php library for khaled.alshamaa inside dompdf library , so

please follow these steps:

1- download the ar-php library for khaled.alshamaa from the following link
http://www.ar-php.org/ (its free arabic Library with LGPL license)

2 - extract and upload I18N folder inside dompdf folder

3- open Glyphs.php file in this path

               \dompdf\I18N\Arabic 

search

              public function utf8Glyphs($str, $max_chars = 50

replace to

             public function utf8Glyphs($str, $max_chars = 150

4-in text_renderer.cls.php file
dompdf/include/text_renderer.cls.php

before this line

       $this->_canvas->text($x, $y, $text 

add this code

 if ( ! class_exists( 'I18N_Arabic' ) ){

require_once( DOMPDF_DIR . "/I18N/Arabic/Glyphs.php" );
$Arabic = new I18N_Arabic_Glyphs('Glyphs');
$text = $Arabic->utf8Glyphs($text);

    }

also you should use any custom arabic font in your css file
this will fix Arabic problem forever and will display arabic letter correctly
example : احمد
will appear
احمد
not
د م ح ا

thanks
hope add this solution to next update @bsweeney

@bsweeney
Copy link
Member

@t3rep-com interesting, we'll definitely take a look!

@101t
Copy link

101t commented Feb 7, 2016

@t3rep-com , it is support Arabic, It is work perfectly Thank you a lot !!
شكرا لك
💯

@ramonleenders
Copy link

How can we make this work in version 0.7.0? I had to change 1 line to prevent an error:

$Arabic = new \I18N_Arabic_Glyphs('Glyphs');

Located in /dompdf/dompdf/src/Renderer/Text.php (instead of /dompdf/include/text_renderer.cls.php)

Unfortunately, my DOMPDF is not outputting 1 of the characters. When I var_dump the text (var_dump($text); exit;), I DO see the characters though. So for some reason, my DOMPDF is not rendering these characters (or this font?). Anyone knows what to do here?

I'm using @t3rep-com method BTW, but for 0.7.0 as stated, not 0.6.x

@101t
Copy link

101t commented Feb 14, 2016

You are right, after hard word I moved my project to run with new library called mPDF, it is more stable and powerful in Arabic Language. :'(

@t3rep-com
Copy link

@ramonleenders maybe the font you are using not good for Renderer try using this font
http://www.mediafire.com/download/wggzhazjqre7a3g/DINNextLTArabic-Medium.zip
Also, please, attach a pic to this problem

@ramonleenders
Copy link

@t3rep-com OK, I extracted this .ttf into

/dompdf/dompdf/lib/fonts

I did not install any extra font. Should I have any other font related files?

What should my (extra) CSS be, to render the font? I'm still getting blank output. I can attach a pic (picture), but it's empty. Normal/english characters DO render! So it's not a DOMPDF problem, it's just not rendering these characters/the font. My computer is full English and I have not installed any extra fonts, not on my computer not within DOMPDF (except the DINNextLTArabic-Medium you just provided).

@t3rep-com
Copy link

hi @ramonleenders
i wanna ask about that , Are you using html template and css file to output pdf file ? if yes
you should extracted DINNextLTArabic-Medium.ttf font in same style.css file found , add embed font by @font-face in css file
e.x add this in your css file

@font-face {
    font-family: 'DINNextLTArabic-Medium';
    src: url('DINNextLTArabic-Medium.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
}

and add DINNextLTArabic-Medium.ttf in same style.css path

@ramonleenders
Copy link

Yeah, I'm using HTML and CSS. I used your code, added the .ttf and also added this

@page { font-family: 'DINNextLTArabic-Medium'; }

Still doesn't seem to work... Perhaps someone can set up a sample project where all this IS working?

@bsweeney
Copy link
Member

@ramonleenders you'll need to load the font into dompdf before it can actually be used. The loading process parses the font to generate the font metrics used for layout. You can load fonts using the load_font.php script or, as indicated by @t3rep-com, using the @font-face CSS rule.

Take a look at the Unicode How-to for an overview of the process.

@ramonleenders
Copy link

OK, I figured out that if a div/span/element is in BOLD (font-weight: bold), it does not render the arabic characters. Is there a way to actually use bold font weight?

Now I got that figured out, I need to know why this I18N_Arabic_Glyphs is replacing my "&" into "&;". Really annoying of course. Anyone else having this issue too? It's doing this in all cases, so in Arabic usage and normal usage.

And one more thing, for some reason when using the I18N_Arabic_Glyphs class, it adds extra spaces before the actual text starts.

This is without Arabic Glyphs:

without-glyphs

This is with Arabic Glyphs:

with-glyphs

@bsweeney
Copy link
Member

It depends on how you are loading the font. If you're using @font-face then you'll need to specify the bold version as well as the non-bold version. Something like:

@font-face {
  font-family: 'DINNextLTArabic';
  src: url('DINNextLTArabic-Medium.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DINNextLTArabic';
  src: url('DINNextLTArabic-Bold.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
}

dompdf doesn't support psuedo-bold or psuedo-italic (i.e. faking it using the existing font), so if you don't have a separate font you would just specify the same font file. Something like:

@font-face {
  font-family: 'DINNextLTArabic';
  src: url('DINNextLTArabic-Medium.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DINNextLTArabic';
  src: url('DINNextLTArabic-Medium.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
}

@ramonleenders
Copy link

OK, I will take care of the bold somehow. That's not my biggest issue. The other 2 seem to be disturbing, anyone knows what to do with them? As the Arabic language is all about aligning to the right, it's quite annoying if the characters have white space..

@saniya-gazala
Copy link

@t3rep-com , it is support Arabic, It is work perfectly Thank you a lot !!
شكرا لك
💯

can you please guide me I'm trying this in CodeIgniter and error is such file doesn't exist

@saniya-gazala
Copy link

thank you it works fine for me

I 'm working with symfony and I found finally a solution to my example with mixed french and arabic language in table with dompdf
in the project make command :
composer require ar-php/ar-php
open the file Glyphs.php in the follow path :

          ` \vendor\ar-php\ar-php\I18N\Arabic

`
search the follow function :

          `public function utf8Glyphs($str, $max_chars = 50`

replace with :

         `public function utf8Glyphs($str, $max_chars = 150`

replace :

public function utf8Glyphs($str, $max_chars = 150, $hindo = true)
    { 
        $str = str_replace(array("\r\n", "\n", "\r"), " \n ", $str);
        $str = str_replace("\t", "        ", $str); 
		

to remove the accent of char that it can produce some errors , insert the follow code :

public function utf8Glyphs($str, $max_chars = 150, $hindo = true)
    {
        $str = str_replace(array("\r\n", "\n", "\r"), " \n ", $str);
        $str = str_replace("\t", "        ", $str);
		
		$a = array('À', 'Á', 'Â', 'Ã', 'Ä',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'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ', 'Ά', 'ά', 'Έ', 'έ', 'Ό', 'ό', 'Ώ', 'ώ', 'Ί', 'ί', 'ϊ', 'ΐ', 'Ύ', 'ύ', 'ϋ', 'ΰ', 'Ή', 'ή');
		$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
		
		$str = str_replace($a, $b, $str); 

save and close the file.
open the file :

		`\vendor\dompdf\dompdf\src\Renderer\Text.php`

add the follow line :

		`use Arphp\Glyphs as Glyphs;`

before this line :

  `$this->_canvas->text($x, $y, $text `

add the follow code :

if ( !class_exists( 'I18N_Arabic' ) )
	{  
		$Arabic = new Glyphs('Glyphs');
		$text = $Arabic->utf8Glyphs($text);
	}

I hope it works for you, for me it's functional

thanks alot. it works fine for me

Hey, i need your to help with this line use Arphp\Glyphs as Glyphs; not working where is Arphp in your application?

@gmormorromrom
Copy link

thank you it works fine for me

I 'm working with symfony and I found finally a solution to my example with mixed french and arabic language in table with dompdf
in the project make command :
composer require ar-php/ar-php
open the file Glyphs.php in the follow path :

          ` \vendor\ar-php\ar-php\I18N\Arabic

`
search the follow function :

          `public function utf8Glyphs($str, $max_chars = 50`

replace with :

         `public function utf8Glyphs($str, $max_chars = 150`

replace :

public function utf8Glyphs($str, $max_chars = 150, $hindo = true)
    { 
        $str = str_replace(array("\r\n", "\n", "\r"), " \n ", $str);
        $str = str_replace("\t", "        ", $str); 
		

to remove the accent of char that it can produce some errors , insert the follow code :

public function utf8Glyphs($str, $max_chars = 150, $hindo = true)
    {
        $str = str_replace(array("\r\n", "\n", "\r"), " \n ", $str);
        $str = str_replace("\t", "        ", $str);
		
		$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', '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 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ', 'Ά', 'ά', 'Έ', 'έ', 'Ό', 'ό', 'Ώ', 'ώ', 'Ί', 'ί', 'ϊ', 'ΐ', 'Ύ', 'ύ', 'ϋ', 'ΰ', 'Ή', 'ή');
		$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
		
		$str = str_replace($a, $b, $str); 

save and close the file.
open the file :

		`\vendor\dompdf\dompdf\src\Renderer\Text.php`

add the follow line :

		`use Arphp\Glyphs as Glyphs;`

before this line :

  `$this->_canvas->text($x, $y, $text `

add the follow code :

if ( !class_exists( 'I18N_Arabic' ) )
	{  
		$Arabic = new Glyphs('Glyphs');
		$text = $Arabic->utf8Glyphs($text);
	}

I hope it works for you, for me it's functional

thanks alot. it works fine for me

Hey, i need your to help with this line use Arphp\Glyphs as Glyphs; not working where is Arphp in your application?

saniya gazala
ar-php/ar-php :
This package is abandoned and no longer maintained. The author suggests
using the khaled.alshamaa/ar-php package instead.

khaled.alshamaa/ar-php

Set of functionalities enable Arabic website developers to serve
professional search, present and process Arabic content in PHP
https://packagist.org/packages/khaled.alshamaa/ar-php
good luck

@saniya-gazala
Copy link

saniya gazala ar-php/ar-php : This package is abandoned and no longer maintained. The author suggests using the khaled.alshamaa/ar-php package instead. khaled.alshamaa/ar-php Set of functionalities enable Arabic website developers to serve professional search, present and process Arabic content in PHP https://packagist.org/packages/khaled.alshamaa/ar-php good luck

YES it was my silly mistake , its working fine now but the symbols are also moving to right eg : my parantheises should be like this () but there are like )( any suggestion sir

@gmormorromrom
Copy link

gmormorromrom commented Jun 18, 2021 via email

@saniya-gazala
Copy link

No luck

@saniya-gazala
Copy link

Try specifying in your markup. Le ven. 18 juin 2021 à 14:45, saniya gazala @.***> a écrit :

saniya gazala ar-php/ar-php : This package is abandoned and no longer maintained. The author suggests using the khaled.alshamaa/ar-php package instead. khaled.alshamaa/ar-php Set of functionalities enable Arabic website developers to serve professional search, present and process Arabic content in PHP https://packagist.org/packages/khaled.alshamaa/ar-php good luck YES it was my silly mistake , its working fine now but the symbols are also moving to right eg : my parantheises should be like this () but there are like )( any suggestion sir — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#712 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRYQPOHAQXPSXWP4GFVRATTTNEY3ANCNFSM4AHZDG5A .

i don't want to change the entire pdf to arabic just a part of it ,

@gmormorromrom
Copy link

gmormorromrom commented Jun 19, 2021 via email

@gmormorromrom
Copy link

gmormorromrom commented Jun 19, 2021 via email

@saniya-gazala
Copy link

don't forget the requirements of dompdf Requirements - PHP version 7.1 or higher - DOM extension - MBString extension - php-font-lib - php-svg-lib Note that some required dependencies may have further dependencies (notably php-svg-lib requires sabberworm/php-css-parser). Recommendations - OPcache (OPcache, XCache, APC, etc.): improves performance - GD (for image processing) - IMagick or GMagick extension: improves image processing performance Le sam. 19 juin 2021 à 12:34, saniya gazala @.> a écrit :

Try specifying in your markup. Le ven. 18 juin 2021 à 14:45, saniya gazala @.
> a écrit : … <#m_-1473708801261247347_> saniya gazala ar-php/ar-php : This package is abandoned and no longer maintained. The author suggests using the khaled.alshamaa/ar-php package instead. khaled.alshamaa/ar-php Set of functionalities enable Arabic website developers to serve professional search, present and process Arabic content in PHP https://packagist.org/packages/khaled.alshamaa/ar-php good luck YES it was my silly mistake , its working fine now but the symbols are also moving to right eg : my parantheises should be like this () but there are like )( any suggestion sir — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#712 (comment) <#712 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRYQPOHAQXPSXWP4GFVRATTTNEY3ANCNFSM4AHZDG5A . i don't want to change the entire pdf to arabic just a part of it , — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#712 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRYQPMP43T6BUETMQCLZYTTTRXE3ANCNFSM4AHZDG5A .

thank you so much it really helped.

@huzailjamil
Copy link

You can now use the very latest version of Ar-PHP library (i.e. version 5.1.0) to handle this Arabic text issue in a more clean way with no need to hack dompdf script at all. You only need to preprocess your HTML code before pass it to create your PDF file, the following code snippet may help you resolve this issue (assuming that your page content is saved in the $html variable):

require_once './ar-php/src/arabic.php';
$Arabic = new ArPHP\I18N\Arabic();

$p = $Arabic->arIdentify($html);

for ($i = count($p)-1; $i >= 0; $i-=2) {
    $utf8ar = $Arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1]));
    $html   = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
}

Then pass your HTML into dompdf and stream the output, just like their quick start example (you will replace the 'hello world' string by your $html variable).

We already fixed the issue of replacing & by &; that mentioned by ramonleenders. Also, the new implementation scenario will not generate any extra spaces before the actual text.

I use your solution before loading html but it looks messed up for sure have a look it is showing word "ﺓﺭﻮﺗﺎﻔﻟﺍ ﻢﻗ" instead of "رقم الفاتورة" also in pdf i'm attaching screenshot
image

@bsweeney
Copy link
Member

Going to close this ticket in favor of 2619 as the tracking ticket for the necessary functionality but will review comments here as we build out better support for Arabic.

@huzailjamil
Copy link

@bsweeney got a solution LaravelDaily/laravel-invoices#78 (comment)
Please have a look and its the best solution so far no need to do anything.

@codoffer
Copy link

codoffer commented Feb 21, 2022

You can now use the very latest version of Ar-PHP library (i.e. version 5.1.0) to handle this Arabic text issue in a more clean way with no need to hack dompdf script at all. You only need to preprocess your HTML code before pass it to create your PDF file, the following code snippet may help you resolve this issue (assuming that your page content is saved in the $html variable):

require_once './ar-php/src/arabic.php';
$Arabic = new ArPHP\I18N\Arabic();

$p = $Arabic->arIdentify($html);

for ($i = count($p)-1; $i >= 0; $i-=2) {
    $utf8ar = $Arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1]));
    $html   = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
}

Then pass your HTML into dompdf and stream the output, just like their quick start example (you will replace the 'hello world' string by your $html variable).

We already fixed the issue of replacing & by &; that mentioned by ramonleenders. Also, the new implementation scenario will not generate any extra spaces before the actual text.

Thanks, It works for me. I have used this with laravel 8.x like this

Installed package using composer

composer require khaled.alshamaa/ar-php

Then integrated code (as mentioned above) with controller method

use PDF;
use ArPHP\I18N\Arabic;

class ExampleController  extends Controller {

function downloadPDF(){
        $reportHtml = view('admin.reports.cutomReport', [])->render();
        
        $arabic = new Arabic();
        $p = $arabic->arIdentify($reportHtml);

        for ($i = count($p)-1; $i >= 0; $i-=2) {
            $utf8ar = $arabic->utf8Glyphs(substr($reportHtml, $p[$i-1], $p[$i] - $p[$i-1]));
            $reportHtml = substr_replace($reportHtml, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
        }

        $pdf = PDF::loadHTML($reportHtml);
        return $pdf->download('report.pdf');
}
}

@kharrat
Copy link

kharrat commented Mar 19, 2022

You can now use the very latest version of Ar-PHP library (i.e. version 5.1.0) to handle this Arabic text issue in a more clean way with no need to hack dompdf script at all. You only need to preprocess your HTML code before pass it to create your PDF file, the following code snippet may help you resolve this issue (assuming that your page content is saved in the $html variable):

require_once './ar-php/src/arabic.php';
$Arabic = new ArPHP\I18N\Arabic();

$p = $Arabic->arIdentify($html);

for ($i = count($p)-1; $i >= 0; $i-=2) {
    $utf8ar = $Arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1]));
    $html   = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
}

Then pass your HTML into dompdf and stream the output, just like their quick start example (you will replace the 'hello world' string by your $html variable).

We already fixed the issue of replacing & by &; that mentioned by ramonleenders. Also, the new implementation scenario will not generate any extra spaces before the actual text.

Thanks, It works for me. I have used this with laravel 8.x like this

Installed package using composer

composer require khaled.alshamaa/ar-php

Then integrated code (as mentioned above) with controller method

use PDF;
use ArPHP\I18N\Arabic;

class ExampleController  extends Controller {

function downloadPDF(){
        $reportHtml = view('admin.reports.cutomReport', [])->render();
        
        $arabic = new Arabic();
        $p = $arabic->arIdentify($reportHtml);

        for ($i = count($p)-1; $i >= 0; $i-=2) {
            $utf8ar = $arabic->utf8Glyphs(substr($reportHtml, $p[$i-1], $p[$i] - $p[$i-1]));
            $reportHtml = substr_replace($reportHtml, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
        }

        $pdf = PDF::loadHTML($reportHtml);
        return $pdf->download('report.pdf');
}
}

Works fine for me, thank you 🙏

@learn05
Copy link

learn05 commented Mar 31, 2022

Solution is here

@MAXCOMMANDOS
Copy link

@mahmoud672

شكرا لك ع الخطوات السهله
اتبعت الخطوات وتم تشغيل اللغه العربيه بشكل صحيح
ولكن هناك مشكله في الارقام !!! تظهر الارقام بشكل معكوس
مما يجعلها تُقرا بشكل غير صحيح

https://drive.google.com/file/d/1lvh6-eDGgOfwRI5Ri7zviavfFCjsEF0f/view?usp=sharing

@zaak86
Copy link

zaak86 commented Nov 30, 2022

@mahmoud672

شكرا لك ع الخطوات السهله اتبعت الخطوات وتم تشغيل اللغه العربيه بشكل صحيح ولكن هناك مشكله في الارقام !!! تظهر الارقام بشكل معكوس مما يجعلها تُقرا بشكل غير صحيح

https://drive.google.com/file/d/1lvh6-eDGgOfwRI5Ri7zviavfFCjsEF0f/view?usp=sharing

فقط قم باضافة التالي: Arabic->utf8Glyphs($text, 50, false, false)

كما هو موضح بالشرح

/**
* Convert Arabic string into glyph joining in UTF-8
* hexadecimals stream (take care of whole the document including English
* sections as well as numbers and arcs etc...)
*
* @param string $text Arabic string
* @param integer $max_chars Max number of chars you can fit in one line
* @param boolean $hindo If true use Hindo digits else use Arabic digits <----------هنا
* @param boolean $forcertl If true forces RTL in the bidi algorithm <---------------وهنا
*
* @return string Arabic glyph joining in UTF-8 hexadecimals stream (take
* care of whole document including English sections as well
* as numbers and arcs etc...)
* @author Khaled Al-Sham'aa khaled@ar-php.org
*/

@MohamedRebai41
Copy link

You can now use the very latest version of Ar-PHP library (i.e. version 5.1.0) to handle this Arabic text issue in a more clean way with no need to hack dompdf script at all. You only need to preprocess your HTML code before pass it to create your PDF file, the following code snippet may help you resolve this issue (assuming that your page content is saved in the $html variable):

require_once './ar-php/src/arabic.php';
$Arabic = new ArPHP\I18N\Arabic();

$p = $Arabic->arIdentify($html);

for ($i = count($p)-1; $i >= 0; $i-=2) {
    $utf8ar = $Arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1]));
    $html   = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
}

Then pass your HTML into dompdf and stream the output, just like their quick start example (you will replace the 'hello world' string by your $html variable).

We already fixed the issue of replacing & by &; that mentioned by ramonleenders. Also, the new implementation scenario will not generate any extra spaces before the actual text.

how to make it on wordpress WooCommerce PDF Invoices & Packing Slips plugin ?

Thank you very much dude, this, using the DejaVu Sans font, works perfectly with arabic text

@bsweeney bsweeney removed this from the dompdf-next milestone Jun 8, 2023
@ANazih
Copy link

ANazih commented Aug 2, 2023

$arabic = new Arabic();
$p = $arabic->arIdentify($reportHtml);

    for ($i = count($p)-1; $i >= 0; $i-=2) {
        $utf8ar = $arabic->utf8Glyphs(substr($reportHtml, $p[$i-1], $p[$i] - $p[$i-1]));
        $reportHtml = substr_replace($reportHtml, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]);
    }

Work thank you 👌🏻

@hardik-nandaniya-tis
Copy link

Is problem solved because i am getting
image

instead of الاجرة الاساسية

and same in the Hindi(devanagari)
getting this
img_v3_0277_5c85648f-c6e2-4a7f-ae51-a18c47549ffh
Instead of कम्प्यूटर विज्ञान में स्ट्रिंग अक्षरों के किसी-भी अनुक्रम को कहते हैं:

I am using dompdf version 1.2.1

@TimexPeachtree
Copy link

Is problem solved because i am getting
image

instead of الاجرة الاساسية

and same in the Hindi(devanagari)
getting this
img_v3_0277_5c85648f-c6e2-4a7f-ae51-a18c47549ffh
Instead of कम्प्यूटर विज्ञान में स्ट्रिंग अक्षरों के किसी-भी अनुक्रम को कहते हैं:

I am using dompdf version 1.2.1

For Arabic script you can usee Khaled Al Shamaa ar-php see this way it's working
Comment on same thread works with latest PHP versions
Now the fun part would be to find similar library for devanagari script. If you do pls share it here as a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests