Hi, there is some strange behavior when writing text in arabic. For some reason text from the end of the line goes to beginning. Also if I set documentBuilder.getFont().setBidi(true), in result document text direction in word is not changed. You will see this if you execute my sample code:
char[] arabicChars = IOUtils.toCharArray(arabicStream,
CharEncoding.UTF_8);
Document document = new Document();
DocumentBuilder documentBuilder = new DocumentBuilder(document);
documentBuilder.getFont().setBidi(true);
documentBuilder.getFont().setNameBi("Times New Roman");
documentBuilder.getFont().setSizeBi(14);
documentBuilder.write(String.valueOf(arabicChars));
document.save(outputPath);
There is arabic string that I used in the .txt file in the attachment.
Thanks for your request. It seems the problem occurs because in your string there is combined RTL and LTR text. I linked your request to the appropriate issue in our defect database. But, unfortunately, I cannot promise you a fast fix of this issue, because RTL is quite complicated issue.
As a workaround, you can try avoiding using mixed RTL and LTR strings.
Best regards.
I tried this bug on 3.1.0 version and it seems that it is not fixed yet.
However, I have one more question. When you explicitly call documentBuilder().getFont().setBidi(true) in the result document that paragraph is not aligned on the right and text direction in MS Word is not set to Right to Left. How can I control this?
Hello Ivica!
Thank you for your patience.
This issue has not been resolved yet. I’m sorry for inconvenience. Bidi property can be set on four objects in Aspose.Words document model:
- page setup of a section;
- table row;
- paragraph;
- run.
They all have different semantics. I’ll explain each of them. Bidi of page setup (class PageSetup) in a section means that columns will be counted right-to-left in this section. This makes sense if only section contains more than one column. Bidi of a table row (Row.getRowFormat()) means that left-aligned row will be right-aligned and vice versa. Cells in this row will be counted right-to-left. Bidi of a paragraph (Paragraph.getParagraphFormat()) means that left-aligned paragraph will be right-aligned and vice versa. Runs and other children of this paragraph will be counted right-to-left. Bidi of a run (Run.getFont()) means that individual characters in this run will be output right-to-left. It doesn’t affect paragraph layout.
Regards,
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.