I am working on upgrading docx4j from 3.0.0 to 3.3.0, and I am also updating docx4j-ImportXHTML-nightly-2013-1024 to docx4j-ImportXHTML-3.2.2. I did not change any of the code on my end, as I was hoping it would just work. My code just takes a large string of XHTML and converts it to Word.
After installing the jars, it looks like most of my code still works fine. The only issue I am having is that it is not applying the fonts correctly. I am trying to use Arial Unicode MS, but it keeps it at Times New Roman. I have tried a number of different solutions I've found online, but nothing seems to work. I would rather not change the default font in the source code, as I feel I'm pretty close already.
Here is the relevant part of my code.
- Code: Select all
var sdp = pkg.getMainDocumentPart().getStyleDefinitionsPart();
var styles = sdp.getJaxbElement();
var docDefaults = styles.getDocDefaults();
var defaultRPr = docDefaults.getRPrDefault();
var defaultPPr = docDefaults.getPPrDefault();
var rPr = defaultRPr.getRPr();
var pPr = defaultPPr.getPPr();
var rFonts = rPr.getRFonts();
if(rFonts == null) {
rFonts = factory.createRFonts();
rPr.setRFonts(rFonts);
}
var sz = factory.createHpsMeasure();
var fontSize = new Packages.java.math.BigInteger(18);
sz.setVal(fontSize);
rPr.setSz(sz);
rFonts.setAsciiTheme(null);
rFonts.setEastAsiaTheme(null);
rFonts.setHAnsiTheme(null);
rFonts.setCstheme(null);
rFonts.setAscii("Arial Unicode MS");
rFonts.setEastAsia("Arial Unicode MS");
rFonts.setHAnsi("Arial Unicode MS");
rFonts.setCs("Arial Unicode MS");
After pulling the document and looking at the raw XML, I am noticing that the docDefaults is getting Arial Unicode MS properly, but it doesn't seem to be applying it to the document. Each of the individual rFonts on the rPr's are still getting set to Times New Roman. Is there something that I am missing here? Is there some new way that I have to force the docDefaults to apply?
Thanks in advance.