Here is the code:
public static void copyFontsToCFTMPFolder(String foldePath, boolean... writeFiles) throws Exception {
try {
FontSourceBase[] originalFontSources = FontSettings.getDefaultInstance().getFontsSources();
File srcFolder = new File(foldePath);
File destDir = new File(TMP_DIR); // defined and is one of system fonts folder in PCF
log.info("Is TMP_DIR writable" + destDir.canWrite());
FileUtils.forceMkdir(new File(TMP_DIR + "/fonts"));
FileUtils.copyDirectory(srcFolder, new File(destDir + "/fonts"));
}
catch (Exception | IOException e) {
log.info("Error copying folder" + e);
}
}
In the subsequent code:
SystemFontSource systemFontSource = (SystemFontSource)template.getFontSettings().getFontsSources()[0];
FolderFontSource folderFontSource = new FolderFontSource(TMP_DIR + "/fonts", false, 100);
template.getFontSettings().setFontsSources(new FontSourceBase[] { systemFontSource, folderFontSource });
log.info("Now lenght of systemFontSource:::::>" + template.getFontSettings().getFontsSources().length); // prints the length as 2 with one of my folder source
When I try to print the fonts in both the folders:
public static void printFontInfo1(Document document) {
for (FontSourceBase src : document.getFontSettings().getFontsSources()) {
log.info("The source is::::>" + src.toString());
log.info("Priority is:::>" + src.getPriority());
log.info("Type of font folder is:::>" + src.getType());
for (PhysicalFontInfo fontInfo : src.getAvailableFonts())
log.info(fontInfo.getFullFontName());
}
}
Here is the LOG:
****************************************************
2022-08-03T22:32:33.46-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.462 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : The source is::::>com.aspose.words.SystemFontSource@404e5cf2
2022-08-03T22:32:33.46-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.462 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Priority is:::>0
2022-08-03T22:32:33.46-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.462 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Type of font folder is:::>3
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.479 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Mono Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Mono
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Serif Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Serif
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.480 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Mono Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Sans Mono
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Serif Bold
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : DejaVu Serif
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : The source is::::>com.aspose.words.FolderFontSource@286e39f3
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.481 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Priority is:::>100
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.482 INFO 33 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Type of font folder is:::>1
2022-08-03T22:32:33.48-0700 [APP/PROC/WEB/0] OUT 2022-08-04 05:32:33.482 INFO 33 --- [enerContainer-1] c.s.s.o.p.core.impl.PDFBoxPDFGenerator : PDFBoxPDFGenerator generatePDFAspose()
For the LocalFontSource I purposefully set the priority to 100. If you look at the logs above. the SystemFontSource priority is printed as 0 and the default dejavu fonts are printed. However, the folderfontsource does not print any fonts
I did verify the folder is writable and individually listed the fonts in code and verified the folder listing SSH’ing to my PCF app.
back to square 0 