0
votes

Here's a code to convert docx to pdf

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);

FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toPDF(wordMLPackage, baos);

The problem here is that the generated PDF font is always Times New Roman, which is not the case, the docx template font is actually different, Garamond.

What could be missing or wrong here?

1
Is font Garamond present on your system?JasonPlutext
Yes the font is installed in the systemquarks

1 Answers

1
votes

If a font is not installed on the system or embedded in the document, MS Word performs a silent font substitution. To check whether this is happening for your document, open it in Word, go to Word Options > Advanced > Show Document Content and press the Font Substitution button. (Word 2007)

If the font is embedded in the document, or you already have the font installed on your system, then I do not know what to tell you because ideally docx4j should use that font.

If that isn't the case, i.e. Word is using font substitution (which you can determine using the steps above), you can embed the Garmond font in the document using Word Options > Save > Embed Fonts in File. Run through your conversion program and check again.