Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Apr 11, 2024 10:52 am

Hi
i'm using vscode 1.87.2 and spire.doc 12.3.2 to devlope my code
i want to add a combition of rtl(persian/arabic) and ltl text(english) text in word but it dosent work correctly?
ther first problem is vscode doesnt support rtl langue so i used arabic_reshaper
but the problem is when the text is more than one line for exp. one and half the problem is the first part of text befor english text seperate into two part and first part goes to second line
but it didnt for second text beacuse its more than one line
here is my code
Code: Select all
import arabic_reshaper
from bidi.algorithm import get_display
from spire.doc import *
from spire.doc.common import *

"""
اول second سوم
اول اول اول اول اول دوم اول اول اول اول اول اول اول اول اول اول اول اول اول sssecondddddddd سوم سوم سوم سوم سوم سوم سوم سوم سوم
"""
text = 'اول اول اول اول اول دوم اول اول اول اول اول اول اول اول اول اول اول اول اول sssecondddddddd سوم سوم سوم سوم سوم سوم سوم سوم سوم'

# Create a Document object
document = Document()

# Add a section
section = document.AddSection()

paragraph = section.AddParagraph()
paragraph.Format.IsBidi = True
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left

paragraph.AppendText(text)

text = arabic_reshaper.reshape(text)
text = get_display(text)
print(text)

paragraph = section.AddParagraph()
paragraph.Format.IsBidi = True
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left

paragraph.AppendText(text)

path = "output/test.docx"
document.SaveToFile(path)


here u can find video i provided to wahts the problem
https://drive.google.com/file/d/1qmcb8WHa99WElSuziB7xL5iuwWjS8rtE/view?usp=drive_link

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Fri Apr 12, 2024 9:14 am

Hi,

Thanks for your inquiry.
I understand your scenario, this issue is a bit complicated and difficult to deal with .The VS Code support displaying the RTF language from right to left, but if there are RTL and LTR language in one string, the string will be displayed from left to right.
You use arabic_reshaper to change the order of RTL, but the arabic is always RTL language, when it is written in word together with English(LTR), it will be displayed from left to right, as show in the following screenshot. Therefore, it looks like the text of before english text is separate into 2 parts.
4E77DE15-32B0-4320-9F89-6B095740B565.png


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Apr 12, 2024 10:36 am

so what should i do?
change editor?
or use diffrent reshaper?
or use warp text?

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Mon Apr 15, 2024 8:58 am

Hi,

Do you want to the effect of added paragraph is same as the following screenshot?
222.png

If so, I have reported this issue to our Dev team with the issue ticket number SPIREDOC-10449, they will do further investigation. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Apr 16, 2024 2:26 am

Hi,

According to the feedback from our Dev team, you also need to set bidi to true for TextRange object. I put the complete code below that can achieve the effect you want.
Code: Select all
text = 'اول اول اول اول اول دوم اول اول اول اول اول اول اول اول اول اول اول اول اول sssecondddddddd سوم سوم سوم سوم سوم سوم سوم سوم سوم'

# Create a Document object
document = Document()

# Add a section
section = document.AddSection()

paragraph = section.AddParagraph()
paragraph.Format.IsBidi = True
textRange = paragraph.AppendText(text)
textRange.CharacterFormat.Bidi= True

path = "Output/test.docx"
document.SaveToFile(path)


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Sun Apr 21, 2024 3:30 pm

My warmest thanks
u saved me

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Mon Apr 22, 2024 1:39 am

Hi,

Thanks for your feedback.
I’m glad to hear that your issue has been solved.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc