Aspose.Word Java - SystemFonts not found when deploying in tomcat on ubuntu

Hello,

I´m focussing a problem the loading of fonts within tomcat in ubuntu server.

I want to save the .docx as pdf and Aspose is falling back to Fanwood instead of e.g. Arial.

fc-list is showing me the correct installed fonts and I can see that aspose is also finding the system paths where the fonts are installed are correct:
/usr/share/fonts/truetype/msttcorefonts/

Why Aspose.Word is not recognizing the installed fonts, wenn user and application have all permissions.

Are there other restrictions like e.g. access to tmp-path or something similiar?
I´m using Aspose.Words 22.1.

Thank you and kind regards

@Mike07428 Aspose.Words looks for the fonts in the system font folders. A list of these folders may be seen by the GetSystemFontFolders method. If no supported fonts are found, Aspose.Words will use the built-in default font Fanwood.ttf.
You can explicitly specify the folder where Aspose.Words will look for fonts using FolderFontSource.
You can list the available font using code like the following:

FontSettings settings = new FontSettings();

for (FontSourceBase fs : settings.getFontsSources())
{
    System.out.println(FontSourceType.toString(fs.getType()));
    for (PhysicalFontInfo pfi : fs.getAvailableFonts())
    {
        System.out.println("\t" + pfi.getFullFontName());
    }
}

Thank you for your answer. The SystemFontFolder is found by Aspose:
["","/root/.local/share/fonts","/usr/share/fonts","/usr/local/share/fonts","/usr/X11R6/lib/X11/fonts","/opt/java/openjdk/lib/fonts"]

And within there are following fonts:

/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf: Arial:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
/usr/share/fonts/truetype/msttcorefonts/ariblk.ttf: Arial Black:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/truetype/msttcorefonts/Arial.ttf: Arial:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf: Arial:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf: Arial:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
/usr/share/fonts/truetype/msttcorefonts/arialbi.ttf: Arial:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
/usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf: Arial Black:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf: Arial:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
/usr/share/fonts/truetype/msttcorefonts/ariali.ttf: Arial:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana

Unfortually Aspose is not recognizing it as available fonts - so the output of System.out is empty.
But I don´t unterstand why because I was following all instructions?

@Mike07428 Have you tried to explicitly specify /usr/share/fonts/truetype/msttcorefonts/ folder as FolderFontSource?

Yes, we tried it also and no Systemfonts were loaded.

Does Aspose need some special catalina-policies to load fonts - that could be the only difference left?

@Mike07428 Aspose.Words requires read access to read the font files from the folder. Could you please try suing the following code for testing:

Document doc = new Document("in.docx");
// Specify font settings and sources
doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource("C:\\Temp\\fonts", true) });
// check available fonts
for (FontSourceBase fs : doc.getFontSettings().getFontsSources())
{
    System.out.println(FontSourceType.toString(fs.getType()));
    for (PhysicalFontInfo pfi : fs.getAvailableFonts())
    {
        System.out.println("\t" + pfi.getFullFontName());
    }
}

// Specify warning callback to check whether font substitution is performed.
doc.setWarningCallback(new FontSubstitutionWarningCollector());

// Save document as PDF.
doc.save("out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {

    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            System.out.println(info.getDescription());
    }
}

Thank you for the useful example. The Output is as follows:
SystemFonts
FontsFolder

@Mike07428 Could you please attach the fonts from your font sources? We will check them on our side and provide you more information.

Ok, looks like catalina also needs file-permissions to font-folder:
permission java.io.FilePermission "/usr/share/fonts/-", "read";
permission java.io.FilePermission "/usr/share/fonts", "read";

I think we can close the topic as this point. Thank you

1 Like