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. Image for the cookie policy date
close icon

Font Size for Appended HTML

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.





4 Replies

PR Poornima R Syncfusion Team 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


HK Halvor Kalleberg 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


SS Siva Subramanian Syncfusion Team 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



RA Rajendran Syncfusion Team 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


Loader.
Live Chat Icon For mobile
Up arrow icon