We have some problems regarding the use of Word 2007 Theme fonts using the latest version Aspose.Words (v 11.5.0.0):
reading the font name always returns “Times New Roman”:
var d = new Document(@"Doc.docx");
// get font names
foreach (Run run in d.GetChildNodes(NodeType.Run, true))
Console.WriteLine(run.Font.Name);
setting the font will not be reflected in the save output:
// set font names
foreach (Run run in d.GetChildNodes(NodeType.Run, true))
run.Font.Name = "Arial";
d.Save(@"ArialDoc.docx");
Observing the output file (“ArialDoc.docx”) will notice that only the 1st paragraph has the Arial font set correctly, following paragraphs still have the original Theme fonts.
Secondly, please note that when you specify a font via theme, MS WORD shows theme name in round brackets e.g. Calibri (Body); Aspose.Words preserves Themes, but you cannot get Themes properties. Your request has been linked to the appropriate issue (WORDSNET-3312) in our issue tracking system and you will be notified as soon as this feature is supported. Sorry for the inconvenience.
Moreover, I think, I can suggest you a very simple workaround of this issue. Since DOC format does not support MS Word 2007/2010 Themes, formatting specified in themes will be converted to direct formatting upon saving DOCX to DOC format. So as a workaround, you can save your DOCX document as DOC, then open DOC file and then get font from this document as follows:
Document docx = new Document(@"C:\test\Doc.docx ");
MemoryStream docStream = new MemoryStream();
docx.Save(docStream, SaveFormat.Doc);
Document doc = new Document(docStream);
NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);
foreach (Run run in runs)
{
Console.WriteLine(run.Font.Name);
}
What we are looking for is an easy way to Get/Set the font for a specific Run (see my original post) not to get all the fonts in a Document, as suggested.
Unfortunately the workaround provided does not fit our needs because:
it leads to more overhead (opening DOCX -> saving -> opening to DOC) in terms in memory usage and processing power.
saving to an older document version can introduce loss of formatting problems.
Bogdan:
What we are looking for is an easy way to Get/Set the font for a specific Run (see my original post) not to get all the fonts in a Document, as suggested.
I think, you can easily find a particular word or a phrase in a document using Aspose.Words and change the Font of that particular Run. Please read the following article for more information on how to achieve this: https://docs.aspose.com/words/net/find-and-replace/
Secondly, yes you’re right; but, unfortunately I can’t suggest you any other work around since Aspose.Words currently doesn’t publicly expose Theme’s properties. Rest assured, we will keep you informed of any developments and let you know via this forum thread once Theme’s information is exposed.
Thank you for contacting me via email. I have verified the status of WORDSNET-3312 from our issue tracking system and regret to share with you that the implementation of this new feature (‘Consider exposing theme’s information’) has been postponed till a later date. I am afraid, we cannot push it into production right now because there are many other important issues we have to work on. Rest assured, we will inform you as soon as this issue is resolved. We apologize for the inconvenience.
Hi,
We are developing a tool for generating documents using Aspose.Word 13.2.0. We need to apply a specific theme to various documents, based on a common Word template, which requires modifying the original theme from the template. We were wandering if WORDSNET-3312 has been resolved. Does Aspose.Words now support theme modifications?
Thanks and have a nice day!
Unfortunately, Aspose.Words still does not provide an ability to get themes information. We will consider exposing themes in public API in one of future versions. We will let you know once this functionality is available. We apologize for any inconvenience.