尝试使用 Apache poi 在单词中设置阿拉伯语句子?

trying to set arabic sentence in word using Apache poi?

我正在尝试使用 apache poi api 生成一个 word 文档,我想在 word 中设置一个阿拉伯语句子,但是单词没有保持顺序!!!因为我得到了 بالملك شهادة

public class word {

    public static void main (String [] args) {
    XWPFDocument docx = new XWPFDocument();

    try {

    XWPFParagraph tmpParagraph = docx.createParagraph();   
    XWPFRun tmpRun = tmpParagraph.createRun();   
    tmpRun.setText("شهادة بالملك");
    tmpRun.setFontSize(18);  
    tmpRun.setFontFamily("Calibri (Corps)");
    tmpRun.setBold(true);
    tmpRun.setColor("003894");
    tmpParagraph.setAlignment(ParagraphAlignment.LEFT);
    tmpRun.setUnderline(UnderlinePatterns.SINGLE);
    tmpParagraph.setSpacingAfter(300);

    FileOutputStream fos = new FileOutputStream("Word2.docx");
    docx.write(fos);
    fos.close();
    }
    catch (Exception e ) {
        e.printStackTrace();
    }
    }
}

这是答案:

public class word {

    public enum TextOrientation {
          LTR,
          RTL
       }

    public static void main (String [] args) {

    XWPFDocument docx = new XWPFDocument();

    try {

    XWPFParagraph tmpParagraph = docx.createParagraph();   
    XWPFRun tmpRun = tmpParagraph.createRun();   
    tmpRun.setText("شهادة بالملك");
    tmpRun.setFontSize(18);  
    tmpRun.setFontFamily("Calibri (Corps)");
    tmpRun.setBold(true);
    tmpRun.setColor("003894");
    tmpParagraph.setAlignment(ParagraphAlignment.CENTER);
    tmpRun.setUnderline(UnderlinePatterns.SINGLE);
    tmpParagraph.setSpacingAfter(300);
    setOrientation(tmpParagraph, TextOrientation.RTL);

    FileOutputStream fos = new FileOutputStream("Word2.docx");
    docx.write(fos);
    fos.close();
    }
    catch (Exception e ) {
        e.printStackTrace();
    }
    }

    private static void setOrientation(XWPFParagraph par, TextOrientation orientation) {
          if ( par.getCTP().getPPr()==null ) {
              par.getCTP().addNewPPr();
          }
          if ( par.getCTP().getPPr().getBidi()==null ) {
             par.getCTP().getPPr().addNewBidi();
          }
          par.getCTP().getPPr().getBidi().setVal(orientation==TextOrientation.RTL?STOnOff.ON:STOnOff.OFF);
       }
}