Dear support team,
I’m using Aspose words for java 23.7.
I have a document which contains office math formula. The formula is in Italic.
I would like to change the formula formatting to remove the italics.
The code I’m using to achieve this is as follows
public void removeItalicsForFormulas() throws Exception {
License license = new License();
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("Aspose.Words.lic");
license.setLicense(stream);
Document doc = new Document("C:/tmp/docx/AppBody-Sample-English.docx");
assertNotNull(doc);
Paragraph p = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);
RunCollection rc = p.getRuns();
for (Run r : (Iterable<Run>)rc) {
r.getFont().setColor(Color.green);
}
OfficeMath math = (OfficeMath)doc.getChild(NodeType.OFFICE_MATH, 0, true);
math.setDisplayType(OfficeMathDisplayType.DISPLAY);
math.setJustification(OfficeMathJustification.RIGHT);
for (Node runNode : (Iterable<Node>)math.getChildNodes(NodeType.RUN, true) ) {
Run r = (Run)runNode;
r.getFont().setColor(Color.green);
r.getFont().setItalic(false);
}
doc.save("C:/tmp/Docx/AppBody-Sample-English-NoItalics.docx");
}
Both the input as well as the output documents are attached, together with a file containing the code.
The code is effectively changing the colour of the formula to green, but the italics is not removed.
I also tried math.clearRunnAttr(), but also that has no effect at all. And this method seems to be marked deprecated.
Formulas.zip (384.3 KB)
The inspiration for this piece of code came from this posting
https://forum.aspose.com/t/how-to-extract-all-math-equations-in-word-and-convert-it/255742/5
Any help would be appreciated.
Many thanks