Change default folder for font cache

With aspose.slides for java 19.9, we currently add a folder of fonts and configure it with aspose. We have noticed on linux these fonts get stored in /tmp folder by aspose. We have run into issues where the /tmp folder gets cleared on/by us for various reasons while the program is running and the results from aspose no longer are correct when converting a pptx to pdf.

Is there a way to configure FontsLoader.loadExternalFonts use a folder other than /tmp to store fonts?

@PeteLee,

The LoadExternalFonts() folder does not limits you to store fonts in temp folder. You can save them any where on your disc where it is allowed to access and load fonts from there.

Hi

What I was trying to say is that aspose seems to cache fonts in the /tmp folder and we are asking if it is able to be configured such that aspose can use an alternate directory.

That is, with loadexternalfonts we see the fonts we pass to aspose show up in the /tmp folder, possibly like aspose is using File.createTempFile

Does that make more sense as to what I’m seeing?

@PeteLee,

Yes, it is possible to change directory because this method takes array of load folders as an argument:

FontsLoader.LoadExternalFonts(new string[] { “tmp”, “fonts”, “custom” });

Fonts will be loaded from folder(s) passed to the LoadExternalFonts method.

Hi @Adnan.Ahmad @mudassir.fayyaz

I’m not quite sure I am being clear with my request…

Here is what I see happening:

I call FontsLoader.LoadExternalFonts(new String[] { “/home/myuser/fonts” });

And I see aspose copying those fonts to /tmp with file names like /tmp/+~JF697993709644112113.tmp

I am asking if the FontsLoader class can use a folder to store my fonts that is not /tmp. If so, how can I configure FontsLoader to use an alternative cache directory

@PeteLee,

We have discussed this and it is not possible (setting default temp folder from the public API) at the moment. I have created new feature ticket with ID SLIDESJAVA-37822 and will share good news with you as soon as possible.

@PeteLee,

It seems that you have also reported the same issue in Paid support help desk too. We have already shared the following feedback with you for possible option.

We use java.awt.Font.createFont(Font.TRUETYPE_FONT, inputStream) to load all external fonts. This method creates temporary font files in JDK temporary directory, and we cannot change path to the temporary directory for this method only.

But, we suggest using JDK system property “java.io.tmpdir”, to change the temporary JDK folder (pay attention all temporary JDK files will be created in this folder, not just temporary font files).

Please, use the following code snippet:

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(new String[] { "pathToFonts"});

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

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

The issues you have found earlier (filed as SLIDESJAVA-37822) have been fixed in this update.