I used both openhtmltopdf and itext to generate pdf files, but all arabic words are reverted in pdf, though they are fine in html. The order of words is fine, but inside each word letters are reverted. First letter swaps place with last,etc.
Even if I dont use html, but simple Paragraph in itext with arabic word it is the same.
Anyone knows what could be the problem?
By the way, if I use online tools to convert my html to pdf its totaly fine, words are not reverted.
This is most basic example in itext which does not include html, but only 1 arabic word
String fontPath = "src/main/resources/fonts/Cairo-Regular.ttf"; // Adjust the path to your font
PdfFont arabicFont = PdfFontFactory.createFont(fontPath, "Identity-H", true);
// Step 3: Add Arabic text using the loaded font
String arabicText = "نوع التذكرة"; // Complex text in Arabic meaning "Ticket Type"
Paragraph paragraph = new Paragraph(arabicText)
.setFont(arabicFont) // Set the font for the complex script
.setFontSize(20) // Set font size
.setTextAlignment(TextAlignment.RIGHT); // Align the text to the right for RTL
// Step 4: Add the paragraph to the document
document.add(paragraph);
// Step 5: Close the document
document.close();
You need to sign in to view this answers
Leave feedback about this