We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting Rich Text Control changes Font to Calibri

I notice an issue with setting the structured document tag (Rich Text Attribute) changes the font size to Calibri where it was initially Times New Roman.

Any clue?
FontTest - updated.docx (24.1 KB)
FontTest.docx (28.5 KB)
FontIssue.zip (791 Bytes)

Attached the source, generated word and Java class file.
we are using aspose-java-21.6-jdk17
Appreciate the help.

@mp2 This occurs because in your code you create a Run from scratch and as a result the create Run has default font properties. To fix this simply use an existing Run from sdt. Please see the code below:

private static void updateRichText(Document doc, StructuredDocumentTag sdt, String txtVal) {

    Run run = (Run)sdt.getChild(NodeType.RUN, 0, true);
    sdt.removeAllChildren();

    run.setText(txtVal);

    if (sdt.getLevel() == MarkupLevel.INLINE) {
        sdt.getChildNodes().add(run);
    } else if (sdt.getLevel() == MarkupLevel.BLOCK) {
        Paragraph para = (Paragraph) sdt.appendChild(new Paragraph(doc));
        para.getRuns().add(run);
        sdt.getChildNodes().add(para);
    }
}