getLocale(), ['ar', 'he'])) { $mPDF = new Mpdf([ 'margin_left' => 0, 'margin_right' => 0, 'margin_top' => 0, 'margin_bottom'=> 0, ]); $mPDF->SetDirectionality($direction); $mPDF->SetDisplayMode('fullpage'); $mPDF->WriteHTML($this->adjustArabicAndPersianContent($html)); return response()->streamDownload(fn () => print ($mPDF->Output('', 'S')), $fileName.'.pdf'); } return PDF::loadHTML($this->adjustArabicAndPersianContent($html)) ->setPaper('A4', 'portrait') ->set_option('defaultFont', 'Courier') ->download($fileName.'.pdf'); } /** * Adjust arabic and persian content. * * @return string */ protected function adjustArabicAndPersianContent(string $html) { $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]); } return $html; } }