How to check if the fonts used in the document are found or not?

How to get all of the fonts that are used in the document and check those fonts are found or not? Thanks!

@virgilio.dolosa.rivtech If the document was created using MS Word, you can safely use Document.FontInfos property to get the list of fonts used in the document.
I suppose you are interested in fonts used by Aspose.Words upon rendering to document fixed page formats, like PDF. If so, you can implement IWarningCallback to get a notification when Aspose.Words cannot find the particular font specified in the document and substitutes it.

Yes, I was able to get the list of fonts in there. But how would I know if those fonts are supported or do exists?

I’m creating some kind of diagnostic tool that will report if the docx file they are using can be safely converted to PDF. And usually the output file becomes broken if the font can’t be found in the machine/server running the conversion.

My implementation is after getting the list of the fonts in the document, I’ll check if those fonts can be detected by your library instead of finding out which one have issues during conversion. I believe that will take fewer resources on the server.

@virgilio.dolosa.rivtech You can list all available fonts sources and list the fonts provided by these sources. For example, if you do not specify additional font sources, you can use the following code to get the available fonts:

FontSettings settings = FontSettings.DefaultInstance;
foreach (FontSourceBase fs in settings.GetFontsSources())
{
    foreach (PhysicalFontInfo info in fs.GetAvailableFonts())
    {
        Console.WriteLine(info.FullFontName);
    }
}

Thank you! I just flattened the FontSettings.DefaultInstance.GetFontsSources() through LInQ and was able to get all of the fonts that was found by the library.

1 Like