Using the FontPropertiesManager

Table of Contents

The FontManager is responsible for reading the host system's system fonts and storing the results to aid in font substitution. This process is done statically but can take quite a bit of time depending on the number of fonts installed on the host system. We recommend that you store the system font search results using the FontPropertiesManager. Once the FontPropertiesManager class is initialized it will write the found fonts to disk, ~/.icesoft/icepdf-viewer/ and all subsequent loading will use this cached file. The following code can be used to initialized the FontPropertiesManager class.

// read/store the font cache.

The FontManager instance can also be used to load fonts from the Java Class Path to aid in distributing needed system fonts that would otherwise be difficult to install on the client machine. The following code will load all the fonts found in an 'icepdf-fonts.jar' that has been added to the class path. The package name must also be specified.

FontManager fontManager = FontManager.getInstance();
String jarFontPath = "C:/font-jar/icepdf-fonts.jar";
String jarFontPackage = "my/fonts/package";
// find the font names that are in the jar
List<String> fontNames = readJarFontNames(fontManager, jarFontPath);
// pass the fonts names and path into the font maanger.
fontManager.readFontPackage(jarFontPackage, fontNames);

The readJarFontNames method is defined as:

private static List<String> readJarFontNames(FontManager fontManager, String jarPath) {
    List<String> fonts = new ArrayList<String>();
    try {
        if (jarPath != null) {
            ZipInputStream zip = new ZipInputStream(new FileInputStream(jarPath));
            ZipEntry ze = zip.getNextEntry();
            while (ze != null) {
                String entryName = ze.getName();
                entryName = entryName.substring(entryName.lastIndexOf('/') + 1);
                if (entryName.endsWith(".ttf")
                        || entryName.endsWith(".dfont")
                        || entryName.endsWith(".ttc")
                        || entryName.endsWith(".pfa")
                        || entryName.endsWith(".pfb")
                        || entryName.endsWith(".otf")
                        || entryName.endsWith(".otc")) {
                ze = zip.getNextEntry();
    } catch (IOException e) {
    return fonts;
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.