Muhammad Noman
Muhammad Noman

Reputation: 345

Incorrect rendering of Urdu content in dompdf

I am trying to make a pdf file from a blade view file using dompdf laravel package. all the HTML elements are working fine but the urdu content is rendering separated each character. Like the actual urdu string is ڈاکٹر آصف علی but it is showing like this:

enter image description here

I have tried many fonts which supports urdu language text like DejaVu Sans ad Noto fonts and many other fonts I have tried but could not solve this issue. I have tried some other laravel packages one of them is rendering the urdu text in the correct way but that package don't support html and css styling.

Could anyone please let me know how to solve it?

Upvotes: 0

Views: 500

Answers (1)

Umer Rasheed
Umer Rasheed

Reputation: 148

Dom PDF does not support URDU but in Arabic, There is only 1 way to fix this

Download the ar-php library First form https://www.ar-php.org/ or somewhere you find better.

Use this code to make your content will appear properly

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

$html = "چونکہ اقوامِ متحدہ کی ممبر قوموں نے اپنے چارٹر میں بنیادی انسانی"



$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]);
}

Upvotes: 0

Related Questions