Arabic words are not saved properly in PDF file with landscape orientation

I am creating a PDF file using aspose word. So i am creating table with bidirectional true.
i am facing an issue with orientation of page file. when orientation is portrait then all arabic words looks fine but in Landscape words order gets changed.
Ex. input=التشريعات الرئيسية: القانون رقم (9) لسنة 2007 بإنشاء مؤسسة ا
output=التشريعات الرئيسية: القانون رقم )9( لسنة 2007 بإنشاء مؤسسة ا

File created with landscape orientauin.pdf (34.6 KB)

File created with default orientation.pdf (33.9 KB)

legislation Law 002-2023.docx (19.2 KB)

AsposeCode.zip (2.5 KB)

In attached aspose code if i commnet below three line theg i get accepeted output. but i want PDf in Landscape orientation .

//wordDoc.getFirstSection().getPageSetup().setPaperSize(PaperSize.A4);
//wordDoc.getFirstSection().getPageSetup().setOrientation(Orientation.LANDSCAPE);
//wordDoc.getFirstSection().getPageSetup().setMargins(Margins.NARROW);

Appreciate your support to help me asap.

@rakeshramesh Could you please attach your input DOCX document here for testing? It looks like you have uploaded a wrong DOCX document.
Also, please save the output documents as DOCX on your side and attach them here for our reference. We will check the issue and provide you more information.

Hi Alexey please find below input and output file in word format.
Input file:
AuditDocReport_ar.docx (26.1 KB)

Output file:
download.docx (22.8 KB)

Also please find latest updated code in below zip file. I am using aspose word 23.9 version.
AsposeCode (2).zip (2.5 KB)

@rakeshramesh Thank you for additional information. But unfortunately, strings in the attached code are damaged (not readable). Could you please create a simple console application that will allow us to reproduce the problem and attach it here?

Hi alexey ,

unfortunately i am not able to attach java file here. can you please help me if we can connect on teams. below is my teams id: arjun.patil@morohub.com

please find attached sourcecode.
CreateTable.zip (2.8 KB)

@rakeshramesh Thank you for additional information. You should specify Font.Bidi property to get the desired output. Please try modifying the code like this:

String a1 = "لتشريعات الرئيسية: القانون(1) رقم(9)لسنة 2007 بإنشاء";

Run r = new Run(wordDoc, a1);
r.getFont().setBidi(true);
p1.appendChild(r);
table1.getRows().get(1).getCells().get(2).appendChild(p1);

Hi Alexey,

but, I am aplying this biDi(true) for all paragraphs in document. using below custom function. It should also work right.

public static void setBidi(Node node,boolean isBidi) {
	switch(node.getNodeType()) {
	case NodeType.PARAGRAPH:
		Paragraph paragraph = (Paragraph) node;
		paragraph.getParagraphFormat().setBidi(isBidi);
		break;
	case NodeType.TABLE:
		Table table = (Table)node;
		try {
			// Set Bidi for the entire table
			table.setBidi(true);
				//Set Bidi for all paragraphs in the table
							for (Row row : table.getRows()) {
								for (Cell cell : row.getCells()) {
									for (Paragraph para : cell.getParagraphs()) {
										setBidi(para,isBidi);
									}
								}
							}
		} catch (Exception e) {
			LOGGER.error(e);
		}
		break;
	case NodeType.SECTION:
		Section section = (Section) node;
		for (Paragraph secPara : section.getBody().getParagraphs()) {
			setBidi(secPara, isBidi);;
		}
		break;
	default:
	}
}

@rakeshramesh The code sets Bidi property for paragraphs, but does not set Bidi property for Run nodes.

In that case which ever node direct contains string, for those only we have to set IsBidi(true) . is it correct?

@rakeshramesh The only node that can contain text directly in MS Word documents is Run. Please see our documentation to learn more about Aspose.Words Document Object Model:
https://docs.aspose.com/words/java/aspose-words-document-object-model/

Run.Font.Bidi property specifies whether the contents of this run shall have right-to-left characteristics.
Paragraph.ParagraphFormat.Bidi property specifies whether this is a right-to-left paragraph.

Bidi property should be inherited by run and other inline nodes from the parent paragraph unless Run.Font.Bidi property is explicitly set to false. To make sure RTL content is displayed correctly, it is better to set Run.Font.Bidi property to true explicitely.