Hi.
I have a document that is rendered incorrectly in MS Word 2013: the russian letters appear in reversed order. This happens because run properties contain the following element:
<w:lang w:val="ar-SA" w:eastAsia="ar-SA" w:bidi="ar-SA" />
I have not found a way to manipulate this element using Aspose.Words. Am I missing something?
P. S. You can find the aforementioned document in the attachments.
Hi Artem,
Thanks for your inquiry. Could you please share some more detail about your query along with following detail? We will then provide you more information on this along with code.
- Your input Word document
- Please attach the output Word file that shows the undesired behavior.
- Please attach the expected output Word file that shows the desired behavior.
- Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.
Hi Tahir.
Here’s the code that issustrates what I’m trying to achieve:
var runs = document.GetChildNodes(NodeType.Run, true).Cast();
foreach (var run in runs)
{
if (run.Font != null)
{
run.Font.Bidi = false;
}
if (run.ParentParagraph != null && run.ParentParagraph.ParagraphFormat != null)
{
run.ParentParagraph.ParagraphFormat.Bidi = false;
}
}
I’ve included input file, output file and expected output file in the attachment section.
Hi Artem,
Thanks for sharing the detail. In your case, you need to set the locale of identifier (language) of the formatted characters. Please set the locale as shown in following code example to get the expected output.
Document doc = new Document(MyDir + "input.docx");
var paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>();
foreach (var para in paragraphs)
{
if (para.ParagraphFormat != null)
{
para.ParagraphFormat.Bidi = false;
foreach (Run run in para.Runs)
{
run.Font.Bidi = false;
// Specify the locale so Microsoft Word recognizes this text as Russian.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
run.Font.LocaleId = 1049;
}
}
}
doc.Save(MyDir + "Out.docx");