2

I cant set text direction (note: not text alignment) into right to left using the python-docx library. Do you have any idea to solve this problem?

from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.enum.text import WD_TAB_ALIGNMENT,WD_PARAGRAPH_ALIGNMENT

doc = Document()

style = doc.styles.add_style('rtl', WD_STYLE_TYPE.CHARACTER)
style.font.rtl = True

paragraph = doc.add_paragraph()
paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT

paragraph.add_run('تست Test تست Test',style = "rtl")

doc.save('test.docx')
mehdi parastar
  • 737
  • 4
  • 13
  • 29

1 Answers1

2

I start with calling a doc that is a template with rtl (Normal style is rtl, arabic font etc)

doc = Document(template_path)
p = doc.add_paragraph()
r = p.add_run()
font = r.font
font.complex_script = True
font.rtl = True
r.add_text(text)
Samy
  • 21
  • 2