We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Default font format

I am converting docx documents to html. Now I need to fetch the default (Normal) font format of a template document seperately from the content to use in the sites css.

My problem arises when I do the following:
Font font = doc.Styles[“Default Paragraph Font”].Font; //Same for "Normal"
When I try to get the font name it gives me back “Times New Roman” when it should be “Century Gothic”.

Now the strange thing is that when I use the VS QuickWatch to enumerate the result view of my Aspose.Document variable the font gets updated (correctly).
I tried enumerating the document childnodes myself, adding new items, and lots of other desperate things. None worked.
Even if I enumerate the children and check their font I get “Times New Roman”. None of the runs seems to use “Century Gothic”.
I can however find the “Century Gothic”-font within the document’s FontInfos-list.
When I save the document the (style)font is correct (in MS Word). Even when creating a new document, copying the content (using keepSourceFormatting) Aspose returns “Times New Roman” and in generated MsWord-doc the font is correct."

I am using Aspose.Words 8.0, but when trying with the latest trial the same problem arises.

Hi,


Thanks for your inquiry. I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for inconvenience.

Hi Jonathan,


I think, I can propose 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.

//Open docx
Document docx = new Document("d:/test/myTemplate3.docx");
//Save it in doc format
docx.Save("d:/test/myTemplate3.doc");

//Open doc Word Document
Document doc = new Document("d:/test/myTemplate3.doc");

foreach (var run in doc.GetChildNodes(NodeType.Run, true))
{
Console.WriteLine(((Run)run).Text + " " + ((Run)run).Font.Name);
}
Console.Read();

Hi Imran,


Thank you for your reply. Your post put me in the right direction. For future reference, this is how I solved it using your work around:

Document doc = new Document(“template.docx”);
        <span style="color:blue;">string</span> runText = doc.GetChildNodes(<span style="color:#2b91af;">NodeType</span>.Run, <span style="color:blue;">true</span>).ToArray().Cast<<span style="color:#2b91af;">Run</span>>().First(run => run.Font.StyleName.Equals(<span style="color:#a31515;">"Default Paragraph Font"</span>)).GetText();
        <span style="color:#2b91af;">MemoryStream</span> strDoc = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
        doc.Save(strDoc, <span style="color:#2b91af;">SaveFormat</span>.Doc);
        doc = <span style="color:blue;">new</span> <span style="color:#2b91af;">Document</span>(strDoc);
        Aspose.Words.<span style="color:#2b91af;">Font</span> font = doc.GetChildNodes(<span style="color:#2b91af;">NodeType</span>.Run, <span style="color:blue;">true</span>).ToArray().Cast<<span style="color:#2b91af;">Run</span>>().First(run => run.GetText().Equals(runText)).Font;</pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><br></pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">As you can see, I used Linq 2 times to get a run with the correct style.</pre></div>

Hi Jonathangrisez,

Thank you very much for your feedback. It is great to hear that your issue has been resolved. You are always welcome and please feel free to ask if you have any query in future.


We always welcome constructive response from our customers.


The issues you have found earlier (filed as WORDSNET-3312) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(16)