We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Font Size for Appended HTML

Thread ID:

Created:

Updated:

Platform:

Replies:

92283 Jan 1,2010 04:52 PM UTC Apr 10,2013 07:33 AM UTC ASP.NET Web Forms (Classic) 4
loading
Tags: DocIO
Richard Brown
Asked On January 1, 2010 04:52 PM UTC

I have a report which I create from data in a database. One of the data elements contains some html tags (/ and
ONLY). The problem I have is that I cannot change the Font Size. As AppendHTML does not return a TextRange, I explictly apply a style to the paragraph. It appears that all of the CharacterFormat properties are applied except FontSize. This is true for BulitIn and well as added styles.

For Instance:

HTMLStyle = CType(doc.AddParagraphStyle("InsertedHTML"), IWParagraphStyle)
HTMLStyle.CharacterFormat.FontName = "Arial"
HTMLStyle.CharacterFormat.FontSize = 8
HTMLStyle.CharacterFormat.TextColor = Color.Blue

paragraph = section.AddParagraph()

paragraph.AppendHTML("Test One
")

paragraph.ApplyStyle(HTMLStyle.Name)

My paragraph results in blue, Arial text, but 12 point.

Any help appreciated.





Poornima R [Syncfusion]
Replied On January 5, 2010 04:15 AM UTC

Hi Richard,

Thank you for your interest in Syncfusion products.

We were able to reproduce the mentioned issue.We suspect this could be a defect.We have forwarded this issue to our development team for further analysis.

Could you please report this issue through Direct Trac Developer Support System https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents because you can take the advantage of the expertise of a dedicated support engineer and a guaranteed response time and we hope you will take advantage of this system as well. If you have already reported through Direct trac, please ignore this.

Please let me know if you have any queries.

Regards,
Poornima

Halvor Kalleberg
Replied On April 3, 2013 10:39 AM UTC

Hi I had more or less the same problem as you and actually I found a workaround where im able to change the font type/size when inserting html into a bookmark:

            bk.MoveToBookmark("xmlcontent");   //or whatever your bookmark is named           
            bk.DeleteBookmarkContent(false);

            var document = new WordDocument();
            document.XHTMLValidateOption = XHTMLValidationType.Transitional;
           
            var section = document.AddSection() as WSection;
            var paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 8;  //set linespacing in the paragraph

            section.Body.InsertXHTML("<body style=\"font-size: 8pt; font-family: Arial\">" + model.XmlContent + "</body>");        //wrapping your xmlcontent inside the <Body> tags and specifying font-size or other properties in the style attribute.
   
            var textBodyPart = new TextBodyPart(document); //creating a textbodypart
            while (section.Body.ChildEntities.Count > 0)
            {
                textBodyPart.BodyItems.Add(section.Body.ChildEntities[0]); //moving content from the paragraphs in the section into the textBodyPart object
            }
           
            bk.InsertTextBodyPart(textBodyPart); //finally inserting the textBodyPart into the bookmark

Siva Subramanian [Syncfusion]
Replied On April 9, 2013 05:03 PM UTC

Hi Halvor,

Thank you for your interest in Syncfusion Products.

In AppendHTML(HTML to Doc) method, DocIO converts HTML DOM (document object model) to DocIO DOM and then appends the converted object model to the source paragraph. During this phase, if font information is not specified in the input html string, default value is taken for the converted object model (paragraphs and tables). To resolve this issue, kindly apply the paragraph style before calling AppendHTML() or once after appending HTML we need to manually parse the appended DocIO object model and specify font information directly. Please refer the below code snippet for illustrating the same.

Code snippet:

paragraph = section.AddParagraph()

paragraph.ApplyStyle(HTMLStyle.Name)

paragraph.AppendHTML('<strong>Test</strong> One<br/>')


Please let us know if you have any other questions.

Regards,


Sivasubramanian


Rajendran [Syncfusion]
Replied On April 10, 2013 07:33 AM UTC

Hi Halvor,

 

Thank you for your interest in Syncfusion products.

 

The work around suggested by you with the HTML content contains font size defined inside the body style - font size attribute ("<body style=\"font-size: 8pt; font-family: Arial\">" + model.XmlContent + "</body>"") will work well in both InsertHTML and AppendHTML methods.

 

On an additional note, Both AppendHTML/InsertHTML (HTML to Doc) method, DocIO converts HTML DOM (document object model) to DocIO DOM and then appends/inserts the converted object model to the source paragraph. During this phase, if font information is not specified in the input html string, default value is taken for the converted object model (paragraphs and tables) causing the reported problem. Hence defining the font size inline in the input HTML string will result in expected output.

 

For more information, refer below UG documentation.

http://help.syncfusion.com/ug/asp.net/docio/default.htm#!documents/importingxhtml.htm

 

Please let us know if you have any questions.

 

Regards

Rajendran


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;