In my project, I want to extract a certain page into a PDF file. the page is mostly in the Arabic language.
I am using barryvdh/laravel-dompdf On the first try, there were no characters showing, only question marks instead.
After digging around, I found that I should add the following CSS to my blade page:
* {
font-family: DejaVu Sans, sans-serif;
direction: rtl;
}
now the Arabic letters are showing in the PDF but their order is inverted (ABC is CBA).
after another round of research, I found a solution somewhere that I should add the following into my dompdf/dompdf/src/Renderer/Text.php right before
if (strtolower($style->direction) == 'rtl') {
preg_match_all('/./us', $text, $ar);
$text = join('',array_reverse($ar[0]));
}
// this is added here to know where exactly i put this code
$this->_canvas->text($x, $y, $text
this works and inverts back the text as it should be, but now the letters are separated... (Arabic letters belonging to the same word are connected)
ex: البناء is showing as ا ل ب ن ا ء
this is a known issue for this library that is still not resolved. one of the commentators suggested using the composer library chehivskiy/i18n-arabic and use it as new \I18N_Arabic('Glyphs')
But I keep getting a class not found error. this library does not have any namespaces.
can anyone help me to either find a library that works to transform Arabic HTML to PDF, or maybe try to find a way to fix this library for it to work, or perhaps suggest a way to use a composer non-Laravel library such as chehivskiy/i18n-arabic in a Laravel project.
Thank you so much.