How can I style a Run
and/or Paragraph
to support both RTL and LTR words?
The problem is: I have a complex text which contains both Persian and English words, and I'm trying to create a .docx
document using OpenXML SDK. But, the English words, get RTL too. Assume I have this text:
این متن Javad Amiry انگلیسی ست و باید چپ به راست شود.
I'm expecting to place the text in document like this:
But I'm getting this one:
As you can see, English words are vise-versa! Means, while I'm expecting Javad Amiry
, I'm getting davaJ yrimA
! Do you have any idea to fix that?
The style I'm using is shown below:
var text = "این متن Javad Amiry انگلیسی ست و باید چپ به راست شود.";
var par = new Paragraph();
var pPr = new ParagraphProperties(
new BiDi(),
new Justification { Val = JustificationValues.Both },
new RunFonts {
Ascii = "Arial",
HighAnsi = "Arial",
EastAsia = "Arial",
ComplexScript = "B Mitra",
Hint = FontTypeHintValues.ComplexScript,
},
new FontSize { Val = "24" },
new FontSizeComplexScript { Val = "24" },
new Languages { Bidi = "fa-IR", Val = "en-US", EastAsia = "en-US" }
);
var rPr = new RunProperties(
new RightToLeftText(),
new RunFonts {
Ascii = "Arial",
HighAnsi = "Arial",
EastAsia = "Arial",
ComplexScript = "B Mitra",
Hint = FontTypeHintValues.ComplexScript
},
new FontSize { Val = "24" },
new FontSizeComplexScript { Val = "24" },
new Languages { Bidi = "fa-IR", Val = "en-US", EastAsia = "en-US" },
new BiDi { Val = true }
);
var run = new Run();
run.AppendChild(rPr);
run.AppendChild(new Text(text));
par.AppendChild(pPr);
par.AppendChild(run);
// finally append to the body
body.Append(par);
Thanks in advance.
Run
s. But I'm curious if is there any way, to have them both in oneRun
. Thank you for the consulting. Cheers. +1 – amiry jd