openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

When converting html to PDF all arabic words are reversed

Open Aleksaas opened this issue 1 year ago • 3 comments

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?

Aleksaas avatar Oct 17 '24 08:10 Aleksaas

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.

abolotnov-ion avatar Oct 17 '24 19:10 abolotnov-ion

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.

Aleksaas avatar Oct 17 '24 20:10 Aleksaas

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

mostaf7583 avatar Dec 29 '24 08:12 mostaf7583