Enumarate used Font

Hi,
I need to know all the fonts used in a word document…does you component have this feature?
thanks

We have this information internally, but it is not exposed in the public API. We can consider including it in the public API though. Please give a more detailed description of your task. It will help us to evaluate the necessity of adding this feature.
Best regards,

Ok,
imagine to have a word file and I want to convert it or view it on another computer.
I need to know if the doc file will show properly…may be the doc file contains font not installed on the other computer so the conversion or the viewing will not be “exact”
Hope to described well my problem
Regards

Thanks. So I presume you need a simple string array exposing font names used in a document. I have logged this as a feature request #1359. We will discuss it and inform you of the results in this thread.
Best regards,

This is easily done. I wrote a sample for you.

Document doc = new Document(MyPath + "Font.Names.doc");
// Select all runs in the document.
NodeCollection runs = doc.GetChildNodes(NodeType.Run, true, false);
// Use a hashtable so we will keep only unique font names.
Hashtable fontNames = new Hashtable();
foreach (Run run in runs)
{
    // This adds an entry into the hashtable.
    // The key is the font name. The value is null, we don't need the value.
    fontNames[run.Font.Name] = null;
}
// There are two fonts used in this document.
Assert.AreEqual(2, fontNames.Count);

Hello,

this code doesn’t work correctly. It gives me only a part of the fonts that are actually used in the document.
I attached a simple example that fails for me. It gives me only Times New Roman, Arial, Consolas, Arial Black as a result, but there is also Calibri and Cambria used for some letters.
I also tried looking at the paragraph itself (as the Calibri is the default font for the paragraph), but it still gives me Times New Roman as a result.
Do you know what could be the problem ?

Best regards,
Ireneusz Patalas

Hello

Thanks for your inquiry. In Ms Word you can set font of some text using different approaches – you can change font in style applied to some text; you can select some text and set font (in this case font of particular run of text will be changed); and in MS Word 2007 you can use Themes to set the font. When font is specified via theme, MS Word shows “+” sign at the beginning of theme name. There is no way to read font from Theme using Aspose.Words, that is why you see default font (Times New Roman in our case).
Best regards,

Hello,

thank you for your answer, at least I know why it doesn’t work. I thought it will, because I tried more or less the same using Word Automation before (iterating through paragraphs/words/characters) and it worked there. The only problem was that it’s extremely inefficient, about 10 seconds for a simple document with 8 pages, definitely not an acceptable solution. Anyway, thanks for the answer, I will need to look for a different way to do it.

Best regards,
Ireneusz Patalas

Hi

Thanks for your request. I think, I can suggest you a very simple workaround of this issue. Since DOC format does not support MS Word 2007 Themes, formatting specified in themes is converting to direct formatting. So as a workaround, you can save your DOCX document as DOC, then open DOC file and then get font from this document.
Hope this helps.
Best regards.