danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 360 forks source link

Arabic and English words get mixed up when together in one line #918

Open kenneth-apuyan opened 1 year ago

kenneth-apuyan commented 1 year ago

This issue happens when the line starts with arabic followed by english words. They interchange places or get all mixed up. I already applied the below code : PdfRendererBuilder builder = new PdfRendererBuilder(); builder.useUnicodeBidiSplitter(new ICUBidiSplitter.ICUBidiSplitterFactory()); builder.useUnicodeBidiReorderer(new ICUBidiReorderer()); builder.defaultTextDirection(BaseRendererBuilder.TextDirection.LTR);

a-leithner commented 1 year ago

This seems to be the same issue as discussed in #432. I have experienced this issue before and the solution I have described here has fixed the issue for me. So, in your case, the "RTL here" should be replaced with your Arabic text, "LTR here" with your English insertions.

kenneth-apuyan commented 1 year ago

This seems to be the same issue as discussed in #432. I have experienced this issue before and the solution I have described here has fixed the issue for me. So, in your case, the "RTL here" should be replaced with your Arabic text, "LTR here" with your English insertions.

Thanks :D. It worked on some parts of my template. Sadly, this seems to works only if you know what texts are LTR and RTL i.e. static text. For dynamic text, i.e. provided by a user that will then be embedded to the html template, you don't have any control on it so it could be an arabic text, an english text or a mixed of both. You can't separate them via spans with the LTR/RTL beforehand.