We are using Aspose in Java 11.0.16 on Linux (RHEL 8), Words - v22.7, Imaging - v23.8. Also we are deploying the Java application in the Kubernetes as a container.
Currently we are loading the fonts as below
FontSettings.getDefaultInstance().setFontsFolder(fontsPath, false) at app startup.
I’ve gone through the reference :
(Specify TrueType Fonts Location in Java|Aspose.Words for Java)
So could you help with the sample reference code for caching the fonts to a file and reading it from that file for subsequent calls to improve the performance.
We are blocked with this issue in PROD. emphasized text
@Vudattu21 You can save the parsed font cache using code like the following:
FontSettings.getDefaultInstance().setFontsSources(
new FontSourceBase[] { new FolderFontSource("C:\\Temp\\fonts", true) });
// Save the parsed font catch.
FileOutputStream cache = new FileOutputStream("C:\\temp\\cache");
FontSettings.getDefaultInstance().saveSearchCache(cache);
// .......................
// .......................
// Load cache.
FontSettings.getDefaultInstance().setFontsSources(
new FontSourceBase[] { new FolderFontSource("C:\\Temp\\fonts", true) },
new FileInputStream("C:\\temp\\cache"));
But node, that sources should be the same as when saving font search cache.
Also, if application start even occurs rarely, it is not necessary to catch the fonts, since Aspose.Words reads the font once and then reuse the read information on the subsequent calls.
@alexey.noskov ,
Thanks for your help.
However, we would like to implement the above solution in Kubernetes platform.
We have two approaches?
Approach 1) With above cache solution. What’s the best way to configure the OS specific fonts folder(windows or Linux systems) fonts to write it to a cache file in Kubernetes platform? I mean the path to load the fonts to cache file and read from it.
Is it via NAS path or through Ephemeral storage or via any configuration file ?
If possible provide us the sample reference.
Approach 2) We are creating a container image for the OS related fonts in a folder as a base image. And will use this new image with fonts and build our application specific image.
@alexey.noskov ,
We are blocked with this issue in PROD. emphasized text
@Vudattu21 I suppose the second approach is easier to implement since you can simply use a folder in your docker image as as folder font source.
Aspose.Words cannot use external storages of fonts directly, it will be required to load fonts one by one using StreamFontSource
in case of using external storage. There is .NET example in our documentation how to use fonts stored in S3:
https://docs.aspose.com/words/net/integration-in-aws-lambda/#how-to-use-fonts-stored-in-s3-storage-in-aws-lambda
The approach is similar for Java. So I would suggest to select the second approach and load the fonts from local folder inside your docker image.