Default font format

Last post 01-06-2012, 11:54 AM by imran.rafique. 4 replies.
Sort Posts: Previous Next
  •  01-05-2012, 5:34 AM 353241

    Default font format

    Attachment: Present (inaccessible)
    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.
    Filed under: .docx;.net 4.0;Font Name
     
  •  01-05-2012, 6:55 AM 353258 in reply to 353241

    Re: Default font format

    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.


    Best Regards,
    Imran Rafique
    Support Developer
    Aspose Sialkot Team
    http://www.aspose.com/
    Aspose - Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  01-06-2012, 2:13 AM 353438 in reply to 353241

    Re: Default font format

    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();


    Best Regards,
    Imran Rafique
    Support Developer
    Aspose Sialkot Team
    http://www.aspose.com/
    Aspose - Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  01-06-2012, 2:41 AM 353440 in reply to 353438

    Re: Default font format

    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");
     
                string runText = doc.GetChildNodes(NodeType.Run, true).ToArray().Cast<Run>().First(run => run.Font.StyleName.Equals("Default Paragraph Font")).GetText();
                MemoryStream strDoc = new MemoryStream();
                doc.Save(strDoc, SaveFormat.Doc);
                doc = new Document(strDoc);
                Aspose.Words.Font font = doc.GetChildNodes(NodeType.Run, true).ToArray().Cast<Run>().First(run => run.GetText().Equals(runText)).Font;

    As you can see, I used Linq 2 times to get a run with the correct style.
     
  •  01-06-2012, 11:54 AM 353578 in reply to 353440

    Re: Default font format

    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.



    Best Regards,
    Imran Rafique
    Support Developer
    Aspose Sialkot Team
    http://www.aspose.com/
    Aspose - Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
View as RSS news feed in XML