When running our library jOfficeConvert to convert Word, Excel or PowerPoint documents to PDF, some of the Microsoft Windows fonts may be missing on the machine when running on Linux or Unix servers. We have done some research to identify good substitution fonts and have implemented a mechanism to specify font substitutes within our library.

The suggested font substitutions below are meant to offer possible metric compatible font substitutions for Microsoft fonts. These fonts are specifically designed to be metric compatible with their corresponding Microsoft fonts. The substitutions used here are based on information from this webpage: https://wiki.archlinux.org/index.php/Metric-compatible_fonts

Some of these replacement fonts can be found under the “fonts” folder of our sample demo application after you download and install it on your machine.

Note: the sample above is showing how to set replacement font when converting Word to PDF but it can be easily edited to set replacement fonts when converting from Excel to PDF or converting PowerPoint to PDF.

// This Java Sample Program Converts a Word Document to PDF
// Using the specified substitute fonts if the Microsoft Office fonts are not found on the machine
 
// create a new instance of WordConvertOtions
WordConvertOptions options = new WordConvertOptions();
 
// assign any substitutions using the font family names
 
//Microsoft Office Fonts
// false indicate that the substitution only happens if the original font is not found on the machine
options.setFontSubstitute("Calibri", "Carlito", false);
options.setFontSubstitute("Cambria", "Caladea", false);
options.setFontSubstitute("Courier New", "Cousine", false);
 
//Other common Microsoft fonts
options.setFontSubstitute("Arial", "Arimo", false);
options.setFontSubstitute("Georgia", "Gelasio", false);
// the Liberation font is not shipped with our demo application
options.setFontSubstitute("Arial Narrow", "Liberation Sans Narrow", false);
options.setFontSubstitute("Times New Roman", "Tinos", false);
options.setFontSubstitute("Symbol", "Symbol Neu", false);
options.setFontSubstitute("Wingdings", "URWDings", false);									
 
// Load the document with the options instance
WordDocument wd = new WordDocument("input.doc", options);
 
// Save the document as a PDF file
wd.saveAsPDF("output.pdf");

You can either install these fonts on your Linux machine directly or add the font files to a folder and make that folder accessible to jOfficeConvert during font discovery using the following static method:

WordDocument.setUserFontDirectories(List dirs);