简体   繁体   中英

Keep font when converting DOCX to PDF using Docx4j

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?

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, ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM