Issue with Arabic Text Display in PDF Conversion using Aspose.PDF 24.1.0

We are using Aspose.PDF version 24.1.0 to convert an HTML file to PDF. While the general conversion works, we are facing a critical issue with the display of Arabic text. Specifically, there are large spaces between Arabic words, which severely affects the readability and formatting of the content.

We have tried multiple solutions, including applying custom CSS styles to control the spacing, but none of them resolved the issue.

The HTML content contains both Arabic and English sections, and the problem is only observed in the Arabic text. The English content appears correctly. Additionally, we are using a web font (Amiri) for the Arabic text, but even with standard fonts like Arial, there was an issue with displaying some character’s like (لا) it wasn’t displayed properly.
Here is you will find a screen shoot for specific part that we have a problem in it in the generated pdf file.
image.png (40.6 KB)

also i will attach the html content that we pass it to aspose

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Generation</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Arial', sans-serif;
            font-size: 15px;
            margin: 0;
            padding: 0;
        }

        .header {
            text-align: center;
            padding: 10px 20px;
        }

            .header img {
                max-width: 200px;
            }

        .content {
            padding: 20px;
        }

        .footer {
            text-align: center;
            margin-top: 20px;
            padding: 10px;
            font-size: 12px;
            page-break-inside: avoid;
        }

            .footer table {
                border-top: 2px solid #dfdec3;
                width: 100%;
                margin-top: 10px;
                border-collapse: collapse;
            }

            .footer td {
                padding: 5px;
                font-size: 10px;
                border: none;
                text-align: center;
            }

        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            table-layout: fixed; /* Prevents column width issues */
        }

        th, td {
            padding: 8px;
            border: 1px solid #000;
            text-align: right;
            word-wrap: break-word; /* Ensures content wraps within the cell */
            overflow-wrap: break-word; /* Prevents overflow */
        }

        .rtl {
            direction: rtl !important;
            text-align: right !important;
            font-family: 'Amiri', 'DejaVu Sans', 'Noto Sans Arabic', sans-serif; /* Arabic font */
            font-size: 12px;
            word-spacing: -2px;
        }

        .align-left {
            text-align: left;
        }

        .english {
            direction: ltr;
            text-align: left;
            font-family: 'Arial', sans-serif;
        }

        .page {
            page-break-after: always;
        }

        .note {
            font-size: 12px;
            margin-top: 10px;
        }

        .logo {
            max-width: 200px;
            margin: auto;
        }
    </style>
</head>
<body>
    <!-- Arabic Content -->
    <div class="header">
        <h3>كتاب إثبات تسجيل ملكية نطاق</h3>
    </div>
    <div class="page">
        <div class="content rtl">
            <p>لمن يهمه الأمر,</p>
            <p>بناء على طلب المسجل/المنسق الإداري الحالي تم إصدار هذا الكتاب إلكترونيًا من منصة ** ** وهي أحد منتجات ** (**)، كوكيل تسجيل نطاق ** مرخص من هيئة الاتصالات والفضاء والتقنية (**) للنطاقات المحلية (**). نفيدكم علماً بأن النطاق المذكور أدناه مسجل رسميًا لدينا حسب البيانات التالية:</p>
            <table>
                <tr>
                    <th>اسم النطاق</th>
                    <td>{{DomainName}}</td>
                </tr>
                <tr>
                    <th>تاريخ التسجيل للنطاق</th>
                    <td>{{ActivationDate}}</td>
                </tr>
                <tr>
                    <th>تاريخ انتهاء صلاحية التسجيل للنطاق</th>
                    <td>{{ExpiryDate}}</td>
                </tr>
                <tr>
                    <th>اسم الجهة</th>
                    <td>{{CompanyName}}</td>
                </tr>
                <tr>
                    <th>اسم المسجل</th>
                    <td>{{RegistrantFullName}}</td>
                </tr>
                <tr>
                    <th>البريد الإلكتروني للمسجل</th>
                    <td>{{RegistrantEmail}}</td>
                </tr>
                <tr>
                    <th>اسم المنسق الإداري</th>
                    <td>{{AdminFullName}}</td>
                </tr>
                <tr>
                    <th>البريد الإلكتروني للمنسق الإداري</th>
                    <td>{{AdminEmail}}</td>
                </tr>
            </table>
            <p class="note"><strong>و بناء عليه حرر هذا الكتاب إلكترونيًا بتاريخ: {{CurrentDate}}</strong></p>
            <p class="note"><strong>ملاحظة:</strong> تجدون على موقع المركز ال** لمعلومات الشبكة عبر الرابط التالي بعض البيانات العامة المعلنة والمحدثة عن النطاق: </p>
            
        </div>
        
    </div>
    <!-- English Content (same as before) -->
    <div class="page">
        <div class="header">
            <h3>Domain Ownership Registration Letter</h3>
        </div>
        <div class="content english">
            <p>To whom it may concern,</p>
            <p style="font-size: 13px;">At the request of the current domain registrant/administrative coordinator, this letter was issued electronically from the ** ** platform, a product of ** (**), as a licensed ** domain registration agent by the Communications and Space Technology Commission (**) for local domains (**). The domain mentioned below is officially registered with us according to the following details:</p>
            <table>
                <tr>
                    <th style="text-align: left;">Domain Name</th>
                    <td class="align-left">{{DomainName}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Registration Date</th>
                    <td class="align-left">{{ActivationDate}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Expiry Date</th>
                    <td class="align-left">{{ExpiryDate}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Entity Name</th>
                    <td class="align-left">{{CompanyName}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Registrant Name</th>
                    <td class="align-left">{{RegistrantFullName}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Registrant Email</th>
                    <td class="align-left">{{RegistrantEmail}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Administrative Coordinator Name</th>
                    <td class="align-left">{{AdminFullName}}</td>
                </tr>
                <tr>
                    <th style="text-align: left;">Administrative Coordinator Email</th>
                    <td class="align-left">{{AdminEmail}}</td>
                </tr>
            </table>
            <p class="note"><strong>Accordingly, this letter was issued electronically on: {{CurrentDate}}</strong></p>
            <p class="note"><strong>Note:</strong> You can find publicly available and updated domain information on the ** Network Information Center website:</p>
           
        </div>
        
    </div>
</body>
</html>

@HanaaMohammed

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-44628

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

I’m happy to share some key points that helped me resolve the encountered problems. Hopefully, this will be useful for others facing similar issues.

I encountered issues while converting an HTML file to PDF using Aspose.PDF.Drawing instead of Aspose.PDF, as my HTML content contains images. The primary problems were:

  1. Arabic character spacing issues, especially with certain ligatures.
  2. The “لا” character was not displayed correctly in the generated PDF.

Solutions Implemented

To resolve these issues, I applied the following fixes:

  1. Font Selection
  • I explicitly set the Arabic font in the HTML using Google Fonts:
<link href="https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
  • I also applied styles to enforce its usage in specific parts of the document.
  1. Linux Font Configuration in Docker
    Since the application runs in a Dockerized environment, I ensured that the necessary fonts were installed to support Arabic rendering. I added the following lines to my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN sed -r -i 's/^deb(.*)$/deb\1 contrib/g' /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get install -y ttf-mscorefonts-installer fontconfig
RUN apt-get install -y libgdiplus
RUN fc-cache -fv && \
    rm -rf /var/lib/apt/lists/*
ENV LD_LIBRARY_PATH=/usr/lib

This ensures that the correct fonts are available when rendering the PDF.

I’m sharing these details to make the solution useful for others facing similar problems. If anyone has additional insights or best practices for Arabic text rendering in Aspose.PDF.Drawing, I’d love to hear them!

@HanaaMohammed

Thanks for sharing this information as it would definitely help others facing similar issue. In the meanwhile, we will also keep the ticket investigation ongoing and as soon as we resolve it, we will share our feedback in this forum thread.

1 Like