Common Exceptions and Errors Involving Fonts on Linux

Overview

When Aspose.Slides is used on Linux, font-related issues may occur if the Java process cannot access the required font folders or temporary directory, if no fonts are installed on the system, or if required system libraries such as fontconfig or libfreetype are missing.

This article describes common errors and exceptions related to fonts on Linux and provides solutions for resolving them. It explains how to check access to font and TEMP directories, install the required fonts and libraries, and use FontsLoader to load fonts without installing them system-wide.

Missing Text or Images (EMF or WMF) When Code Is Executed on Linux

This problem occurs in systems with restrictions in these cases:

  1. When there are no fonts installed or when the font folder for the java process cannot be accessed
  2. When the TEMP directory cannot be accessed.

Solution

Check and confirm that access to the TEMP directory and the fonts folder has been granted.

Workaround

Use FontsLoader to load the required fonts without installing them:

FontsLoader.loadExternalFonts(pathToFontsFolders);

If the TEMP directory cannot be accessed, use this code to specify another directory as the TEMP for Java:

String newTempFolder = "pathToTmpFolder";
String oldValue = System.getProperty("java.io.tmpdir");
java.io.File file = new java.io.File(newTempFolder);
if (!file.exists())
    file.mkdir();
System.setProperty("java.io.tmpdir", newTempFolder);
try {

    FontsLoader.loadExternalFonts(pathToFontsFolders);

    Presentation pres = ...
    // ....

} finally {
    System.setProperty("java.io.tmpdir", oldValue);
}

Exception: InvalidOperationException: Cannot Find Any Fonts Installed on the System

This exception occurs when

  1. the Java process cannot access the fonts folder
  2. no fonts have been installed.

Solution

  1. Check and confirm that access to the font folder for the Java process has been granted.

  2. Install some fonts or use FontsLoader.

  3. Install fonts.

    • Ubuntu:

      sudo apt-get update
      sudo apt-get install -y fonts-dejavu-core
      fc-cache -fv
      
    • CentOS:

      sudo yum makecache
      sudo yum -y install dejavu-sans-fonts
      fc-cache -fv
      
    • Using FontsLoader:

      FontsLoader.loadExternalFonts(pathToFontsFolders);
      

Exception: NoClassDefFoundError: Could Not Initialize Class com.aspose.slides.internal.ey.this

This exception occurs on a Linux system that lacks fontconfig and fonts.

Solution

Install fontconfig:

  • Ubuntu:

    sudo apt-get update
    sudo apt-get -y install fontconfig
    
  • CentOS:

    sudo yum makecache
    sudo yum -y install fontconfig
    

Additionally, some open-jdk versions (for example, alpine JDK) also require installed fonts.

  • Ubuntu:

    sudo apt-get install -y fonts-dejavu-core
    fc-cache -fv
    
  • CentOS:

    sudo yum -y install dejavu-sans-fonts
    fc-cache -fv
    

Exception: UnsatisfiedLinkError: libfreetype.so.6: Cannot Open Shared Object File: No Such File or Directory

This exception occurs on a Linux system that lacks the libfreetype library.

Solution

Install libfreetype and fontconfig:

  • Ubuntu:

    sudo apt-get update
    sudo apt-get install libfreetype6
    sudo apt-get -y install fontconfig
    
  • CentOS:

    sudo yum makecache
    sudo yum install libfreetype6
    sudo yum -y install fontconfig