Writing Arabic rtf file with header in Python

Viewed 47

I want to write string from variable into RTF file using python, I know I can use something like this

test = 'file.rtf'
name = "someone"
file = open(test,'w')
file.write("""{\\rtf1\\ansi\\deff0
{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;}
\\b Name: """ + str(name) + """ \\b0\line
}""")
file.close()

but in my case the string is in Arabic language, when I try to edit \ansi and \deff it doesn't work, what can I do to make the header of the RTF file accepts Arabic characters?

Note: I am using Ubuntu

EDIT: for example, when I try this

rtfDoc = 'test.rtf'
out_file = open(rtfDoc, 'w')
out_file.write(
    """{\\rtf1\\ansi\\b البرنامج \\b0\line}""")
out_file.close()

I get this output

البرنامج 

0 Answers
Related