I’m having issues making Cells find new fonts that are added at runtime in rendering a PDF. I’m needing to add them at runtime because we’re using a fonts repository that returns TTF files on-demand, as they’re found in documents, instead of all up-front.
I’ve tried many different approaches:
1. Adding the fonts to the directory specified in the “Aspose.Cells.FontDirExc” location
2. Adding the new fonts as MemoryFontSources to the FontSourceBase[] passed to FontConfigs.setFontSources(…).
I’ve noticed that as long as I haven’t performed ANY Cells calls yet, #1 will work correctly.
It seems as though FontConfigs.setFontSources will only accept ONE item of “MemoryFontSource” as a FontSourceBase. If I add multiple, only the first seems to be found. Should I be able to use more than one MemoryFontSource, or is that approach limited to just one font?
Is there a proper way to dynamically load fonts at runtime, after Cells has had calls in its stack, either from disk or from byte array?
Examples:
#1: Works. Assume document has: Arial, Calibri in it only (pseudo-code):
System.setProperty(“Aspose.Cells.FontDirExc”, tempFontsDir.toAbsolutePath().toString());
addFont(“Arial”); // addFont is custom code that downloads the font and stores it in the directory specified by the FontDirExec JVM arg
addFont(“Calibri”);
Workbook workbook = new Workbook(new ByteArrayInputStream(data));
ByteArrayOutputStream os = new ByteArrayOutputStream();
workbook.save(os, new PdfSaveOptions());
#2: Does NOT work. Same document: Arial, Calibri:
System.setProperty(“Aspose.Cells.FontDirExc”, tempFontsDir.toAbsolutePath().toString());
addFont(“Arial”); // addFont is custom code that downloads the font and stores it in the directory specified by the FontDirExec JVM arg
<span style=“font-family: “Courier New”; font-size: small;”>Workbook workbook = new Workbook(new ByteArrayInputStream(data));
<span style=“font-family: “Courier New”; font-size: small;”>
addFont(“Calibri”);
ByteArrayOutputStream os = new ByteArrayOutputStream();
workbook.save(os, new PdfSaveOptions());