Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem while loading RTL table #3452

Open
alisentinel opened this issue May 1, 2024 · 1 comment
Open

Problem while loading RTL table #3452

alisentinel opened this issue May 1, 2024 · 1 comment

Comments

@alisentinel
Copy link

alisentinel commented May 1, 2024

Hello there,

I've loaded a simple HTML table in Farsi (RTL) language, but I've encountered two problems when trying to render it into a PDF.

The first issue is that instead of printing "ردیف", it prints "ف‌ی‌د‌ر" (reversed and spaced between characters) and the second issue is that making a table RTL is not working!

After searching in this repository, I found that this issue has persisted for several years without being fixed. Some users have suggested that the printing of characters can be fixed by using other libraries like ar-php, but the other issue still remains unresolved or not reported.

I have attached some screenshots to better illustrate the problem.

Code to reproduce the bug:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once __DIR__ . '/vendor/autoload.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;

$html = <<<EOD
    <!DOCTYPE html>
    <html lang="fa">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1, maximum-scale=1, viewport-fit=cover, shrink-to-fit=no">
    <style type="text/css" media="screen">
    @font-face {
        font-family: 'IranSans';
        font-style: normal;
        font-weight: normal;
        src: url(https://f2test.click/bot/assets/fonts/IRANSansX-Regular.ttf) format('truetype');
    }
    @font-face {
        font-family: 'IranSans';
        font-style: bold;
        font-weight: bold;
        src: url(https://f2test.click/bot/assets/fonts/IRANSansX-Bold.ttf) format('truetype');
    }
    * { direction: rtl; }
    body { font-family: IranSans, DejaVu Sans; direction: rtl; }
    table td, table th {
        border: 1px solid #000;
        text-align: center;
        vertical-align: middle;
        direction: rtl;
    }
    table tr:nth-child(odd) {
        background-color: #f2f2f2;
    }
    </style>
    </head>
    <body dir="rtl" style="direction: rtl;">
    <h1>Hi All</h1>
    <p>Lorem ipsum</p>
    <table cellpadding="1" align="center" style="width:100%; direction: rtl;">
        <tr style="background-color: #424242;">
            <th style="color: #fff; width: 6%;">ردیف</th>
            <th style="color: #fff; ">آیدی عددی</th>
            <th style="color: #fff; ">نام کاربر</th>
            <th style="color: #fff; ">نام کوچک</th>
            <th style="color: #fff; ">نام خانوادگی</th>
            <th style="color: #fff; width: 7%;">پوزیشن</th>
            <th style="color: #fff; ">موجودی</th>
        </tr>
        <tr><td>1</td><td>-1</td><td>سیستم</td><td>سیستم</td><td>سیستم</td><td>0</td><td>0</td></tr>
        <tr><td>2</td><td>-2</td><td>معاملات سیستمی</td><td>معاملات سیستمی</td><td>معاملات سیستمی</td><td>0</td><td>0</td></tr>
        <tr><td>5</td><td>5582339738</td><td>هادی</td><td>شاهین</td><td>حیدری</td><td>0</td><td>100,000,000</td></tr>
        <tr><td>6</td><td>72686053</td><td>دادا</td><td>مهدی</td><td>محمدی</td><td>0</td><td>4,616,000</td></tr>
        <tr><td>7</td><td>1603762437</td><td>منتظر</td><td>پیام</td><td>منتظری</td><td>1</td><td>1,129,992,000</td></tr>
        <tr><td>8</td><td>6851927881</td><td>پوریا</td><td>حامد</td><td>حامدی</td><td>0</td><td>30,032,000</td></tr>
    </table>
    </body>
    </html>
    EOD;

$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);

$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();

Excepted result:
image
(As you see ردیف short numbers 1,2,5,... is on the right side and texts rendered correctly.)

DOMPDF rendered result:
image
(The table is still LTR and the texts are not correctly rendered)

@bsweeney
Copy link
Member

bsweeney commented May 2, 2024

Dompdf does not yet support fully support the complex text layout features required to render Farsi correctly. Additionally, fully supporting RTL in layout will require additional work on the layout engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants