We have an application which generates a pdf file from a word template.
Implementation:
Our application listens to an oracle message queue which contains information about the file details.
This file is a .doc template which is stored in S3 bucket. Based on the file information, we fetch the template using a rest client and convert it to ASPOSE PDF document replacing with the data and attachment tags and then store the generated pdf document to the S3 bucket. The UI reads the PDF doc from S3, where all the fonts and formats aredifferent from the initial template .doc we use in higher ENV.
The same is working fine in local ENV.
QA
Template file
PDF generated file (Note : Scratched off the Name for security reasons)
@ravishat Could you please attach the source template and output PDF here for testing? We will check the issue and provide you more information.
Also please note that Aspose.Words should have access to the font files when its performing DOC to PDF conversion. Please check the Specify TrueType Fonts Location and Aspose.Words Integration in AWS Lambda articles.
@ravishat Thank you for additional information. It looks like fonts used in your source document are not available in the environment where the conversion is performed. In this case Aspose.Words substitutes the fonts that are not available. You can implement IWarningCallback to get a notification when font substitution is performed.
I work with Ravisha. Based on your suggestion, we did IWarningCallback. There is no log of any substitution.
As previously mentioned we have sent the fonts folder (we use Aspose words Java and currently evaluating Aspose PDF java).
Our application is a Spring Boot app hosted on a PCF platform in a linux container (if that helps)
String path = new ClassPathResource("/fonts").getFile().toString()
FontSettings.getDefaultInstance().setFontsFolder(path, false);
The output PDF document has a totally different font than the source word document. (Word Document has simple Times New Roman, the output PDF file contains, the following set of fonts: (image attached)
@sathsy As I can see the output PDF document attached by @ravishat is produced by Aspose.PDF not by Aspose.Words. Also, in your screenshot I see that Fanwood font is used in output PDF. This for is the last resort font used by Aspose.Words when it cannot find any other fonts in the environment. In this case Aspose.Words should warn about font substitution, if IWarningCallback is properly implemented and set. For example see the following code:
// You can use this code to check what fonts are available in your environment.
for (FontSourceBase src : FontSettings.getDefaultInstance().getFontsSources())
{
for (PhysicalFontInfo fontInfo : src.getAvailableFonts())
System.out.println(fontInfo.getFullFontName());
}
// Open document
Document doc = new Document("C:\\Temp\\in.docx");
// Set warning callback
doc.setWarningCallback(new FontSubstitutionWarningCollector());
// Save the output document.
doc.save("C:\\Temp\\out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
System.out.println(info.getDescription());
}
}
We have added the code as per your suggestion. What’s weird is that when its printing the fonts it printed the times new roman but then it complains again that its not finding it.
Here is the code snippet and the corresponding logs.
public Document extractData(ClientHttpResponse response) throws IOException {
try {
String path = new ClassPathResource("/fonts").getFile().toString();
FontSettings fontSettings = new FontSettings();
FolderFontSource folderFontSource = new FolderFontSource(path, true);
Document document = new Document();
document.setFontSettings(fontSettings);
SystemFontSource systemFontSource = (SystemFontSource)
document.getFontSettings().getFontsSources()[0];
for (String systemFontFolder : SystemFontSource.getSystemFontFolders()) {
log.info("Here is your System Font Folder" + systemFontFolder);
} document.getFontSettings().getSubstitutionSettings().getDefaultFontSubstitution().setEnabled(false);
document.getFontSettings().setFontsSources(new FontSourceBase[] { systemFontSource, folderFontSource });
document.setFontSettings(fontSettings);
document = new Document(response.getBody());
FontInfoCollection fontInfos = document.getFontInfos();
document.setWarningCallback(new AsposeDocumentToPDDocumentConverter.FontSubstitutionWarningCollector());
log.info("printing document font information AFTER loading options");
log.info("***********************************************************************************");
fontInfos.forEach(fontInfo -> printFontInfo(fontInfo));
log.info("***********************************************************************************");
return document;
}
catch (Exception cause) {
throw new IOException(cause);
}
}
private void printFontInfo(FontInfo fontInfo) {
log.info("AltName:" + fontInfo.getAltName());
log.info("Name:" + fontInfo.getName());
log.info("Font Family:" + fontInfo.getFamily());
}
LOGS:
22-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder
2022-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/home/vcap/.local/share/fonts
2022-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/share/fonts
2022-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/local/share/fonts
2022-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/X11R6/lib/X11/fonts
2022-07-29T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/home/vcap/app/.java-buildpack/open_jdk_jre/lib/fon
ts
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.530 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : printing document font information AFTER loading options
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.530 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : **********************************************************************************
*
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.530 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Times New Roman
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Symbol
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Arial
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Book Antiqua
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Calibri
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:AS Circular Light
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:Georgia
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.531 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:EngravrsRoman BT
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Century Schoolbook
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Verdana
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Tahoma
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Calibri Light
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:2
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Courier New
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:3
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Wingdings
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:0
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : AltName:
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:Cambria Math
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:1
2022-07-29T14:47:36.53-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.532 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : **********************************************************************************
*
2022-07-29T14:47:37.44-0600 [APP/PROC/WEB/0] OUT Font 'Times New Roman' has not been found. Using 'DejaVu Serif' font instead. Reason: table substitution.
2022-07-29T14:47:37.73-0600 [APP/PROC/WEB/0] OUT Font 'Book Antiqua' has not been found. Using 'DejaVu Serif' font instead. Reason: font info substitution.
2022-07-29T14:47:38.38-0600 [APP/PROC/WEB/0] OUT Font 'Symbol' has not been found. Using 'DejaVu Sans' font instead. Reason: font info substitution.
2022-07-29T14:47:38.41-0600 [APP/PROC/WEB/0] OUT Font 'Courier New' has not been found. Using 'DejaVu Sans Mono' font instead. Reason: table substitution.
@ravishat Thank you for additional information. However, in your code you use Document.getFontInfos() this property returns font info read from fontTable from the document, i.e. fonts used in the document. To get fonts available in your environment, you should use code like this:
// Set font settings
document.setFontSettings(fontSettings);
// Print the fonts available in the font sources specified in the document font settings.
for (FontSourceBase src : document.getFontSettings().getFontsSources())
{
for (PhysicalFontInfo fontInfo : src.getAvailableFonts())
System.out.println(fontInfo.getFullFontName());
}
Hello @alexey.noskov
I have tried printing with the above. Here are the logs.
After analyzing more we dont have any fonts at the locations which got printed in the logs. Also, we don’t have permissions to access those paths to place the font folder as this is a PCF env and we are using .jar file to deploy. Could you please suggest on how we can get the fonts loaded ?
c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder
2022-07-31T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/home/vcap/.local/share/fonts
2022-07-31T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/share/fonts
2022-07-31T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/local/share/fonts
2022-07-31T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/usr/X11R6/lib/X11/fonts
2022-07-31T14:47:36.26-0600 [APP/PROC/WEB/0] OUT 2022-07-29 20:47:36.260 INFO 15 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Here is your System Font Folder/home/vcap/app/.java-buildpack/open_jdk_jre/lib/fon
ts
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.527 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.528 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.528 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Mono Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Serif Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Serif
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Serif
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Serif
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Mono Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Sans Mono
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Serif Bold
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Serif
2022-07-31T17:58:10.52-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Name:DejaVu Serif
2022-07-31T17:58:10.53-0600 [APP/PROC/WEB/0] OUT 2022-07-31 23:58:10.529 INFO 17 --- [enerContainer-1] c.s.s.o.p.c.a.DocumentResponseExtractor : Font Family:DejaVu Serif
2022-07-31T17:58:12.47-0600 [APP/PROC/WEB/0] OUT Font 'Times New Roman' has not been found. Using 'DejaVu Serif' font instead. Reason: table substitution.
2022-07-31T17:58:12.86-0600 [APP/PROC/WEB/0] OUT Font 'Book Antiqua' has not been found. Using 'DejaVu Serif' font instead. Reason: font info substitution.
2022-07-31T17:58:13.80-0600 [APP/PROC/WEB/0] OUT Font 'Symbol' has not been found. Using 'DejaVu Sans' font instead. Reason: font info substitution.
2022-07-31T17:58:13.84-0600 [APP/PROC/WEB/0] OUT Font 'Courier New' has not been found. Using 'DejaVu Sans Mono' font instead. Reason: table substitution.
@ravishat Thank you for additional information. As I can see from your log, the only available font family in your environment is DejaVu. Since, there are no other available fonts, Aspose.Words substitutes the fonts in your document with DejaVu.
Please make sure the fonts folder you have specified in the code is available and accessible by your code.
fontSettings.getDefaultInstance().setFontsSources(
new FontSourceBase[] { new FolderFontSource(folder, true, 1), new SystemFontSource(0) });`
None of the above made any difference.
Is there a documentation with PCF /linux stack and loading folderfontsource?
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Mono Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Mono
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Serif Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Serif
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Mono Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Sans Mono
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Serif Bold
2022-08-01T06:41:22.08-0700 [APP/PROC/WEB/0] OUT DejaVu Serif
@sathsy There are no additional requirement for specifying a folder fonts source in Linux. Please see our documentation to learn how to specify fonts folder location.
In your code you specify fonts folder properly, the problem might occur because folder is not accessible. So please check the following in your code:
Make sure the specified fonts folder exists;
Make sure folder is not empty;
Make sure you can read files from the specified folder.
Thank you. I can list the TTF/TTC font files from the packaged jar while deployed to PCF.
I did take a look at StreamFontSource and MemoryFontSource. I might have to look at StreamFontSource for all the fonts used in the source word document.
I wonder what the other poster did to get PCF to read the custom packaged fonts folder (LocalFontSource, setting priority to FontFolderSource - I have tried many options).
There seems to be some nuance with how spring boot + PCF reads the folder of fonts.
@sathsy Thank you for additional information. Unfortunately, Aspose.Words does not read fonts packed into JAR. So in your case you should either copy the fonts into the OS file system or use StreamFontSource or MemoryFontSource to get fonts from your JAR file and provide them to Aspose.Words.
@alexey.noskov our document could have multiple fonts. Having looked at the StreamFontSource, is there an elegant way not to mention every single font?
I could get all the fonts present in the document using: Document.getFontInfos()
Would it be then loading each of those fonts used in the document using:
private static class StreamFontSourceFile extends StreamFontSource {
public FileInputStream openFontDataStream() throws Exception {
return new FileInputStream(getFontsDir() + "**Kreon-Regular.ttf**");
}
}
Thank you. We used the above Streamsource implementation and verified that the folder is accessible in the environment.
try
{
//getFontsFromFolder is from the above implementation given by Alexey
fontSettings.setFontsSources(getFontsFromFolder(path));
document.setFontSettings(fontSettings);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setEmbedFullFonts(true);
document.save(pdfOutputStream, pdfSaveOptions);
log.info("Getting font info after saving as PDF....");
}
catch (Exception e)
{
log.info("Error converting to PDF generatePDFAspose::" + e);
}
We still have the same issue where font substitution happens and i see the message from warning call back and the generated PDF has only the following fonts
It still only has the last resort fanwood fonts!
Is there anything else I am missing when document.save(pdfOutputStream,pdfSaveOptions); is called. It doesnt matter if I embed the fonts or not.
Also before saving it as PDF, i tried printing all the document fonts and system fonts (stream source fonts) and it has all my packaged fonts.
@sathsy Could you please attach your input document and the fonts, which are packaged into your JAR? We will try to emulate your situation and reproduce the problem.
Also, could you please try copying the packaged fonts into a temporary folder in your environment and use this temporary folder as fonts folder source?
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.
@sathsy Could you please attach your fonts, which are packaged into your JAR? We will try to emulate your situation and reproduce the problem. Maybe the problem is in the fonts themselves.