Hi Team,
I am facing a an issue where if all of my variables in a docx document are not in same font, then few of them don't get replaced with actual values.
Below is the piece of code I use to replace variables and generate pdf, please advise what is missing
tempDir = correctDirectoryPath(tempDir);
bytes = IOUtils.toByteArray(inputStream);
file = new File(tempDir + fileName + this.formatter.format(new Date()) + ".pdf");
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new ByteArrayInputStream(bytes));
VariablePrepare.prepare(wordMLPackage);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
if (params != null) {
fields = new HashMap<>(params);
documentPart.variableReplace((HashMap<String, String>) fields);
}
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
List<SectionWrapper> sectionWrappers = replaceHeaders(params, wordMLPackage);
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
if (!file.exists()) {
file.createNewFile();
}
os = new FileOutputStream(file);
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
System.out.println("Done!");
return file;