When converting html to PDF all arabic words are reversed
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?
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.
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.
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