barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.67k stars 967 forks source link

Arabic charachers is reversed #734

Closed sagadsalem closed 3 years ago

sagadsalem commented 3 years ago

hi Arabic characters are in reversed its show like:

ابحرم

should show like:

مرحبا

i have default configration but in my template i use:

<html lang="ar">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        body {
            font-family: "DejaVu Sans", sans-serif !important;
        }
    </style>
</head>
<body>
<h1>مرحبا</h1>
</body>
</html>
jackpit93 commented 3 years ago

I have the same problem, after generate PDF showed ????? character in page. image

html:

<!doctype html>

<html lang="fa">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>The HTML5 Herald</title>
    <meta name="description" content="The HTML5 Herald">
    <meta name="author" content="SitePoint">

</head>

<body>
    <h1>به نام خدای بخشنده و مهربان</h1>
</body>
</html>

implementation: image

mRamadan0101 commented 3 years ago

install this https://github.com/mRamadan0101/dompdf

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf. If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.

mukesh17mj commented 3 years ago

Facing the same issue.

Creating the PDF, all the other fonts like English, Hindi etc looks fine but the Arabic font is reversed when creating the pdf.

الإغتيالات والسموم الكيميائية is change to ةيئايميكلا مومسلاو تالايتغإلا

MouhcineMAHFOUD commented 2 years ago

I faced the same issue, no solution worked for me yet.

AhmedMarcom commented 1 year ago

i face issue when i use arabic font is reversed any solution for that thanks ...???

ICodingStack commented 4 months ago

finally i got the solution This setup is designed to help you integrate custom fonts with mPDF in a Laravel project, specifically using fonts for Arabic text rendering.

  1. Download the Required Fonts: Navigate to [Google Fonts]( [https://fonts.google.com/selection/embed] and download the font files you need.
  2. Install the Necessary Package: Run the following command to install the mpdf/mpdf package:

composer require mpdf/mpdf

  1. Add Fonts to the Public Folder: Place the downloaded font files into the public directory of your Laravel project. For example:

/public/fonts/Amiri-Regular.ttf /public/fonts/Amiri-Bold.ttf

  1. Update the Layout Page to Include Font-Face: Modify your layout page to include the custom fonts using CSS. Here's an example of how to define the @font-face for your fonts:

`@font-face { font-family: "Amiri"; src: url('{{ asset('/fonts/Amiri-Regular.ttf') }}') format('truetype'); font-weight: normal; font-style: normal; }

@font-face { font-family: "Amiri"; src: url('{{ asset('/fonts/Amiri-Bold.ttf') }}') format('truetype'); font-weight: bold; font-style: normal; }

body { font-family: 'Amiri'; margin: 0; padding: 0; background-color: #f4f7f6; color: #333; direction: rtl; / RTL direction for Arabic / } `

  1. Implement the PDF Generation Function: Create a function in your Laravel controller to generate PDFs using mPDF, configuring it to use the custom fonts:

`public function generatePDFAR(Quote $quote) { $companyProfile = CompanyProfile::first(); // Fetching the first company profile entry

// Setup custom font directory and font data configuration
$fontDirs = [public_path('fonts')];
$fontData = [
    'amiri' => [
        'R' => 'Amiri-Regular.ttf',
        'B' => 'Amiri-Bold.ttf'
    ]
];

$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$defaultFontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$defaultFontData = $defaultFontConfig['fontdata'];

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',
    'orientation' => 'P',
    'autoScriptToLang' => true,
    'autoLangToFont' => true,
    'fontDir' => array_merge($defaultFontDirs, $fontDirs), // Merge default font directory with your custom directory
    'fontdata' => $fontData + $defaultFontData, // Merge default font data with your custom font data
    'default_font' => 'amiri' // Set default font to Amiri
]);

$view = view('quotes.quotes-ar', compact('quote', 'companyProfile'))->render(); // Render view to HTML string
$mpdf->WriteHTML($view);
return $mpdf->Output('quotes_ar.pdf', 'I'); // Output PDF to browser

} `

Feel Free to Ask Any Questions good luck :)