Thanks @alexey.noskov, i will add this log and check. Please check if below is correct.
If it is related to access issue, could you please let me know which folder is good for fonts to be placed so that Aspose.word can access it.
Aspose.Words.Document userDocument = new Aspose.Words.Document(userDocumentMemoryStream);
DocumentBuilder builder = new DocumentBuilder(userDocument);
// Set warning callback
userDocument.WarningCallback = new WarningCallback();
FontSettings FontSettings = new FontSettings();
// Set font source warning callback
FontSourceBase source = FontSettings.GetFontsSources()[0];
FontSourceWarningCollector callback = new FontSourceWarningCollector();
source.WarningCallback = callback;
// Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
// Fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
// FontSettings.SetFontSources instead.
LogDiagnosticMessage("Setting Font Source - Start");
FontSettings.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"/usr/share/fonts/truetype/msttcorefonts", true) });
LogDiagnosticMessage("Setting Font Source - Complete");
//Print available fonts
PrintAvaialbleFonts(FontSettings);
// Set font settings
userDocument.FontSettings = FontSettings;
@KCSR No the code is not quite correct. Please modify it like this:
FontSettings FontSettings = new FontSettings();
// Create font sources Set font source warning callback
SystemFontSource systemFontSource = new SystemFontSource();
FolderFontSource folderFontSource = new FolderFontSource(@"/usr/share/fonts/truetype/msttcorefonts", true);
systemFontSource.WarningCallback = new FontSourceWarningCollector();
folderFontSource.WarningCallback = new FontSourceWarningCollector();
// Note that this setting will override any default font sources that are being searched by default. Now only these folders will be searched for
// Fonts when rendering or embedding fonts. To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
// FontSettings.SetFontSources instead.
LogDiagnosticMessage("Setting Font Source - Start");
FontSettings.SetFontsSources(new FontSourceBase[] { systemFontSource, folderFontSource });
LogDiagnosticMessage("Setting Font Source - Complete");
It depend on your application and environment setup. So there is no general recomendations.
@alexey.noskov - Below is my PrintAvailableFonts() method and it looks like Aspose is not able to get available fonts from font source base folders.
public static void PrintAvaialbleFonts(FontSettings fs)
{
LogDiagnosticMessage("PrintAvaialbleFonts Started");
foreach (FontSourceBase fsb in fs.GetFontsSources())
{
LogDiagnosticMessage("Font Source Base Type : " + fsb.Type);
foreach (PhysicalFontInfo pfi in fsb.GetAvailableFonts())
{
LogDiagnosticMessage("Font Full Name : " + pfi.FullFontName);
}
}
LogDiagnosticMessage("PrintAvaialbleFonts Completed");
}
Below are the logs that i see - It is not printing the "Font Full Name : " + pfi.FullFontName that is present in second foreach loop in the above method.
@KCSR Does FontSource.WarningCallback shows any warnings? The warnings can give you a clue why Aspose.Words cannot load the fonts from specified sources.
@alexey.noskov - Below is my FontSourceWarningCollector callback and i did not see any warnings in my logs related to cannot load fonts from specified sources.
public class FontSourceWarningCollector : IWarningCallback
{
public readonly WarningInfoCollection FontSubstitutionWarnings = new WarningInfoCollection();
/// <summary>
/// Called every time a warning occurs during processing of font source.
/// </summary>
public void Warning(WarningInfo info)
{
FontSubstitutionWarnings.Warning(info);
Console.WriteLine("{0} - TOA Service Diagnostic - Font Substitution - {1}", DateTime.Now, info.Description);
}
}
@KCSR Unfortunately, it is difficult to say why Aspose.Words cannot read the fonts from the specified folder. Please try copying the font into another folder and use this folder as font source. Also, please try copying the fonts from the problematic folder into another environment and check whether fonts can be read.
@alexey.noskov - Why are we not able to print the fonts name from SystemFontSource? Which folder is this?
As you mentioned there might be issue accessing Font folder that we are setting but Aspose should be able to access SystemFontSource folder right?
Also - From below screen it looks like, Aspose is able to read āFanwoodā folder, do we know where is font is located and can we copy our fonts to the same folder? image.png (4.6 KB)
Hi @alexey.noskov - i was able to print system font folders as shown below. But i am not able to print fonts in this folder, donāt know if fonts exist in these folders.
This is the code i am trying to print fonts inside the system font folders.
LogDiagnosticMessage("PrintAvaialble System Fonts Started");
foreach (string systemFontFolder in SystemFontSource.GetSystemFontFolders())
{
LogDiagnosticMessage("System Font folder is : " + systemFontFolder);
FolderFontSource folderFontSource = new FolderFontSource(systemFontFolder, true);
foreach (PhysicalFontInfo pfi in folderFontSource.GetAvailableFonts())
{
LogDiagnosticMessage("Font Full Name from System Font Folder : " + pfi.FullFontName);
}
}
@KCSR You can try getting files from these folders to check whether there are any fonts:
foreach (var path in Directory.GetFiles(@"C:\Temp\"))
{
Console.WriteLine(path); // full path
Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
}
If you see in below screenshot the first font in FontsFolder is āAndale Monoā and I donāt have āCalibriā in my fonts package.
Could you please let me know during FontSubstitution, why Aspose is Substituting āArialā which is second font in fontsfolder, when it did not find āCalibriā?
This is FontSubstitution warning info message - Font āCalibriā has not been found. Using āArialā font instead. Reason: font info substitution.
@KCSR The reason of substitution is mentioned in the warning message, in you case it is " font info substitution". The substitution in such case is determined by the information from FontInfo stored in the document. Aspose.Words takes in account font panose, unicode ranges, codepages, pitch, charset and weight of the font to select a suitable substitution.