使用poi jar写入docx文件时如何默认设置"Latha"字体

How to set "Latha" font by default while writing docx file using poi jar

我需要使用 apache poi 创建一个 docx 文件,并且我需要将其字体设置为 Latha。下面是我的代码,但当我使用 setfontfamily("Latha") 时它不起作用。 Latha 是泰米尔语字体。

    XWPFDocument document = new XWPFDocument();
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File("PageCounter.docx"));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();
        run.setText(replaceAll2);
        run.setFontFamily("Latha");
        run.setFontSize(10);
        document.write(out);
    } catch (IOException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
    }

系统正在写入文件,但 unicode 文本显示为框。

这是 3.7 中的错误: http://apache-poi.1045710.n5.nabble.com/NPE-setting-font-family-for-a-XWPFRun-td5050524.html

但在 3.8 中工作(目前处于 Beta 阶段): https://issues.apache.org/bugzilla/show_bug.cgi?id=52288