numbers inveresed in text
ikramooe opened this issue · comments
Which function is this? Are we talking about he utf8Glyphs() method?
It will be highly appreciated if you share the code snippet to reproduce this issue.
yes it is the utf8Glyphs
i am using your package in dompdf in order to render arabic text
here's th code i'm using
if ( !class_exists( 'I18N_Arabic' ) )
{
$Arabic = new Glyphs('Glyphs');
$text = $Arabic->utf8Glyphs($text);
}
$this->_canvas->text($x, $y, $text,
$font, $size,
$style->color, $word_spacing, $char_spacing);
It looks like you are using an outdated version of the Ar-PHP library! You have to get the latest release by following these instructions:
https://github.com/khaled-alshamaa/ar-php#download-and-install
Then update your code snippet to be something like this:
require_once 'path/to/ar-php/src/Arabic.php';
$Arabic = new \ArPHP\I18N\Arabic();
$text = $Arabic->utf8Glyphs($text);
$this->_canvas->text($x, $y, $text, $font, $size, $style->color, $word_spacing, $char_spacing);
Please let me know if this works for you so that I can close this issue.
i am using laravel so i did
use ArPHP\I18N\Arabic as Arabic;
Well, utf8Glyphs()
method has 4 parameters:
https://ar-php.org/github/docs/classes/ArPHP-I18N-Arabic.html#method_utf8Glyphs
In your case, to stop using Hindo digits, you can set $hindo parameter to be false:
$text = $Arabic->utf8Glyphs($text, 50, false);
On the other hand, could you please share one of your $text inputs before you process it via the utf8Glyphs()
method? I need to investigate why that weird mess in ordering Arabic words in your final PDF output.
Please just save the $text content in a text file and attaché that file here in this conversation. Screenshot is not going to help me in this checking ;-)
file_put_contents('example.txt', $text);
file_put_contents('example.txt', $text); $text = $Arabic->utf8Glyphs($text); $this->_canvas->text($x, $y, $text, $font, $size, $style->color, $word_spacing, $char_spacing);
trying this code didn't work i got this file
example.txt
however this is the text i want to render it is saved in the database
`ستجرون فحوص تتطلب وجودكم في العيادة لعدة ساعات حيث أن الفحوص تمر بعدة مراحل.
إذا أردتم مزيدا من المعلومات يمكنكم الإتصال بأمانة العيادة
يرجى عدم إرتداء العدسات اللاصقة والميكاب على الأقل 24 ساعة قبل الفحوص
لا يسمح بدخول المرافقين إلا في حالة قاصر ( ولي الأمر إجباري) أو شخص مسن
احضار يطاقة الموعد (يمكنكم نسخه )مع بطاقة التعريف يوم الفحص
`
Dear ikramooe,
Your latest output shows that the utf8Glyphs() method did the expected function (i.e., converting Arabic string into glyph joining in UTF-8 hexadecimal stream).
Please note that the dompdf library still has an issue supporting RTL text check this issue. So, using tags like <ol> will not work as expected (order number on the left side).
Therefore, you may apply this workaround solution using the $forcertl parameter in the utf8Glyphs() method:
require_once 'dompdf/autoload.inc.php';
require_once 'ar-php/src/Arabic.php';
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set('defaultFont', 'DejaVu Sans');
$dompdf = new Dompdf($options);
$arabic = new \ArPHP\I18N\Arabic();
$html = file_get_contents('example.txt');
$html = $arabic->utf8Glyphs($html, 120, false, true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream('example', array('Attachment' => false));
You can find below the example.txt file content:
<div align="right">
ملاحظات
</div>
<div align="right">
ستجرون فحوص تتطلب وجودكم في العيادة لعدة ساعات حيث أن الفحوص تمر بعدة مراحل.
</div>
<div align="right">
إذا أردتم مزيدا من المعلومات يمكنكم الإتصال بأمانة العيادة
</div>
<div align="right">
1 يرجى عدم إرتداء العدسات اللاصقة والميكاب على الأقل 24 ساعة قبل الفحوص<br/>
2 لا يسمح بدخول المرافقين إلا في حالة قاصر ( ولي الأمر إجباري) أو شخص مسن<br/>
3 احضار يطاقة الموعد (يمكنكم نسخه )مع بطاقة التعريف يوم الفحص<br/>
</div>
Please note that <div> tags should go in separate lines because of a bug in the current version 6.2 of the Ar-PHP library, and we will solve it in the next version.
Here is a screenshot of the PDF output:
Finally, please make sure to use Dompdf version 1.2.1 or later to address the critical 0day vulnerability of the Remote Code Execution via remote font installation.
Please share testing values of $x, $y, $font, $size, $style->color, $word_spacing, and $char_spacing variables so I can reproduce your case and help you in resolving the problem ;-)
First, the Canvas object provides direct access to the underlying PDF writer's back end. As such, you can't use it to render HTML. Any styling on the text has to be made manually. So, writing HTML into the PDF like you're attempting to do with the DIV element won't work. It will just write out the plain text at the specified x and y coordinates, even without word wrap!