Free Support Forum - aspose.com

Print Details of What Fonts are Present in a Word DOCX Document using C# .NET Code | FontInfos

Hello,
I work with Aspose Words .NET in version 20.10
When I use the “FontInfos” function to retrieve the fonts used on the document, I end up with other fonts.
On this example, I only use the “Arial” “Font” and yet with “fontInfos”, I get 4 “Calibri, Times New Roman, Arial, Calibri Ligth” fonts. Is there a solution to only have the “Font” used?

Here is my code
var docInfo = new Document(Path.Combine(folder, fileName));
var listeFont = docInfo.FontInfos;

and the file
TestFont.zip (8.6 KB)

Thanks for your help
Sylvain

@SylvainAxonCable,

You can use the following C# code of Aspose.Words for .NET API to print the details of what fonts are present in a Word document.

Document doc = new Document("C:\\Temp\\TestFont\\TestFont.docx");

FontInfoCollection fonts = doc.FontInfos;
// The fonts info extracted from this document does not necessarily mean that the fonts themselves are
// used in the document. If a font is present but not used then most likely they were referenced at some time
// and then removed from the Document
for (int i = 0; i < fonts.Count; i++)
{
    Console.WriteLine($"Font index #{i}");
    Console.WriteLine($"\tName: {fonts[i].Name}");
    Console.WriteLine($"\tIs {(fonts[i].IsTrueType ? "" : "not ")}a trueType font");
}

For the sake of any correction in Aspose.Words API, we have logged this problem in our issue tracking system with ID WORDSNET-21442. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for any inconvenience.

Hello,
Thank you for your reply.
The problem is normal for most of the documents, but I created the document. And I didn’t remove any font, I just put “Arial”.

So I will be able to understand for “Arial” and “Calibri Ligth”.
But I’m looking for a function to just find the fonts used in the document, not find all the fonts that are passed.

Thank you
Sylvain

@SylvainAxonCable,

We have logged these details in our issue tracking system and will keep you posted here on any further updates.

Thank you so much
Sylvain