laravel-dompdf: Arabic RTL support is not working

While before using loadHTML echoing the output html its getting RTL alignment with it. After calling this function not getting RTL layout properly.

$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML($html1);
return $pdf->stream('invoice.pdf',array('Attachment'=>0));

Find screen shots for reference

dompdf dompdf1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24

Most upvoted comments

im working with laravel 5.7 & barryvdh/laravel-dompdf 0.8.4 fixed arabic letters as below:-

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

vendor\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 vendor/dompdf/dompdf/src/Render/Text.php

before class name class Text extends AbstractRenderer add this

include DOMPDF_DIR . “/I18N/Arabic/Glyphs.php”; use I18N_Arabic_Glyphs;

before this line

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

add this code

if ( ! class_exists( ‘I18N_Arabic’ ) ){ $Arabic = new I18N_Arabic_Glyphs(‘Glyphs’); $text = $Arabic->utf8Glyphs($text);

}

in ur pdf file add this style

body{
  font-family: DejaVu Sans, sans-serif;
}

I am able to fix the issue by using mpdf library.

  1. Use the mpdf library. In laravel use package https://github.com/niklasravnsborg/laravel-pdf
  2. Use the font-family: “XB Riyaz” with dir=”rtl” attributes

http://www.solutionsbased.in/laravel-arabic-content-display-issue-in-the-pdf/

@mRamadan0101

Many thanks IT work with me. You are super star

I followed mRamadan0101 solution and created a fork: https://github.com/anasbakro/dompdf