This project has moved and is read-only. For the latest updates, please go here.

Special characters

Jan 9, 2012 at 10:50 AM
Edited Jan 9, 2012 at 10:53 AM

Hi, i've been having problems with special characters.

If i use the following HTML:

<P><FONT size=7 face="courier new">Ac&ccedil;&atilde;o</FONT></P>

...the above HTML will look something like this on a web page:

Acção

But the OpenXml component will generate a Word document, where the special characters never appear on the selected font: "courier new". It will allways fall back to the document's default font: Calibri.

Any ideias?

Jan 11, 2012 at 5:40 PM
Edited Jan 11, 2012 at 5:45 PM

Hi everyone. Thanks a lot for the help.

Here's the solution: on the file \HtmlToOpenXml\HtmlConverter.ProcessTag.cs, find the method ProcessFont and change it to this:

        private void ProcessFont(HtmlEnumerator en)
        {
            List<OpenXmlElement> styleAttributes = new List<OpenXmlElement>();
            ProcessContainerAttributes(en, styleAttributes);

            string attrValue = en.Attributes["size"];
            if (attrValue != null)
            {
                uint fontSize = ConverterUtility.ConvertToFontSize(attrValue);
                if (fontSize != 0L)
                    styleAttributes.Add(new FontSize { Val = fontSize.ToString(CultureInfo.InvariantCulture) });
            }

            attrValue = en.Attributes["face"];
            if (attrValue != null)
            {
                styleAttributes.Add(new RunFonts { Ascii = attrValue, HighAnsi = attrValue });
            }

            if (styleAttributes.Count > 0)
                htmlStyles.Runs.MergeTag("<font>", styleAttributes);
        }

 

The solution is in the HighAnsi = attrValue declaration.

Thanks.

 

 

Jan 31, 2012 at 9:37 AM
Edited Jan 31, 2012 at 9:38 AM

How can i use HtmlConverter.ProcessTag.cs

I have this file but the Dll is added so it's throw so many errors.

I am using  HTMLtoOpenXML.dll v1.4.2

this is my string coming from database

string Desc =<span style="font-style: italic; font-family: times new roman,times,serif; color: #ff66cc; font-size: 36pt; font-weight: bold">Test2</span>

 text50.Text = Desc;

How to apply Font name and font size

this is my code:

string Desc =<span style="font-style: italic; font-family: times new roman,times,serif; color: #ff66cc; font-size: 36pt; font-weight: bold">Test2</span>

 text50.Text = Desc;


MainDocumentPart mainPart = document.MainDocumentPart;                           

HtmlConverter converter = new HtmlConverter(mainPart);                           

Body body = mainPart.Document.Body;                           

var paragraphs = converter.Parse(text50.Text);                           

for (int h = 0; h < paragraphs.Count; h++)                           

{                               

run50.Append(paragraphs[h]);                   

  }             

 

 

Thanks