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

When converting html to PDF all arabic words are reversed #984

Open
Aleksaas opened this issue Oct 17, 2024 · 3 comments
Open

When converting html to PDF all arabic words are reversed #984

Aleksaas opened this issue Oct 17, 2024 · 3 comments

Comments

@Aleksaas
Copy link

I use implementation 'com.openhtmltopdf:openhtmltopdf-pdfbox:1.0.10' to convert html to PDF. In HTML everything is ok, but in generated PDF letters in every Arabic word are reversed. نوع التذكرة becomes ةركذتلا عون. Is there any way to fix this? Or it is a bug?

@abolotnov-ion
Copy link

having the same issue. Interestingly, if you add Arabic text in the sandbox, everything generates properly. I can't figure out what I do wrong compared to the code in the sandbox.

@Aleksaas
Copy link
Author

Aleksaas commented Oct 17, 2024

Its interesting that free itext version has the same issue, but with paid version problem is solved. So its general problem that appears in multiple pdf libraries.

@mostaf7583
Copy link

String htmlString = 
    "<html lang=\"ar\">\n" +
    "<head>\n" +
    "    <meta charset=\"UTF-8\" />\n" +
    "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n" +
    "    <title>سورة الفلق</title>\n" +
    "    <style>\n" +
    "        @font-face {\n" +
    "            font-family: 'Amiri';\n" +
    "            src: url('file:///Amiri-Regular.ttf');\n" +
    "        }\n" +
    "        body {\n" +
    "            font-family: 'Amiri', serif;\n" +
    "            direction: rtl;\n" +
    "            text-align: right;\n" +
    "            background-color: #f9f9f9;\n" +
    "            color: #333;\n" +
    "            padding: 20px;\n" +
    "            margin: 0;\n" +
    "        }\n" +
    "        .verse {\n" +
    "            margin-bottom: 20px;\n" +
    "        }\n" +
    "        .verse-number {\n" +
    "            font-weight: bold;\n" +
    "            color: #555;\n" +
    "        }\n" +
    "    </style>\n" +
    "</head>\n" +
    "<body>\n" +
    "    <div class=\"verse\">\n" +
    "        <span class=\"verse-number\">١</span> قُلْ أَعُوذُ بِرَبِّ ٱلْفَلَقِ\n" +
    "    </div>\n" +
    "    <div class=\"verse\">\n" +
    "        <span class=\"verse-number\">٢</span> مِن شَرِّ مَا خَلَقَ\n" +
    "    </div>\n" +
    "    <div class=\"verse\">\n" +
    "        <span class=\"verse-number\">٣</span> وَمِن شَرِّ غَاسِقٍ إِذَا وَقَبَ\n" +
    "    </div>\n" +
    "    <div class=\"verse\">\n" +
    "        <span class=\"verse-number\">٤</span> وَمِن شَرِّ ٱلنَّفَّٰثَٰتِ فِى ٱلْعُقَدِ\n" +
    "    </div>\n" +
    "    <div class=\"verse\">\n" +
    "        <span class=\"verse-number\">٥</span> وَمِن شَرِّ حَاسِدٍ إِذَا حَسَدَ\n" +
    "    </div>\n" +
    "</body>\n" +
    "</html>"; 

I tried providing the font path and it worked

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

No branches or pull requests

4 participants
@Aleksaas @mostaf7583 @abolotnov-ion and others