I found the base concept to convert in this link , and I created the following method to convert rtf to html . it converts the text format options correctly.
Here is the method which converts rtf to html , u can edit as per ur need
public static string ConvertToHtml(RichEditBox richEditBox)
{
string text, strColour, strFntName, strHTML;
richEditBox.Document.GetText(TextGetOptions.None, out text);
ITextRange txtRange = richEditBox.Document.GetRange(0, text.Length);
strHTML = "<html>";
int lngOriginalStart = txtRange.StartPosition;
int lngOriginalLength = txtRange.EndPosition;
float shtSize = 11;
// txtRange.SetRange(txtRange.StartPosition, txtRange.EndPosition);
bool bOpened = false, liOpened = false, numbLiOpened = false, iOpened = false, uOpened = false, bulletOpened = false, numberingOpened = false;
for (int i = 0; i < text.Length; i++)
{
txtRange.SetRange(i, i + 1);
if (i == 0)
{
strColour = txtRange.CharacterFormat.ForegroundColor.ToString();
shtSize = txtRange.CharacterFormat.Size;
strFntName = txtRange.CharacterFormat.Name;
strHTML += "<span style=\"font-family:" + strFntName + "; font-size: " + shtSize + "pt; color: #" + strColour.Substring(3) + "\">";
}
if (txtRange.CharacterFormat.Size != shtSize)
{
shtSize = txtRange.CharacterFormat.Size;
strHTML += "</span><span style=\"font-family: " + txtRange.CharacterFormat.Name + "; font-size: " + txtRange.CharacterFormat.Size + "pt; color: #" + txtRange.CharacterFormat.ForegroundColor.ToString().Substring(3) + "\">";
}
if (txtRange.Character == Convert.ToChar(13))
{
strHTML += "<br/>";
}
#region bullet
if (txtRange.ParagraphFormat.ListType == MarkerType.Bullet)
{
if (!bulletOpened)
{
strHTML += "<ul>";
bulletOpened = true;
}
if (!liOpened)
{
strHTML += "<li>";
liOpened = true;
}
if (txtRange.Character == Convert.ToChar(13))
{
strHTML += "</li>";
liOpened = false;
}
}
else
{
if (bulletOpened)
{
strHTML += "</ul>";
bulletOpened = false;
}
}
#endregion
#region numbering
if (txtRange.ParagraphFormat.ListType == MarkerType.LowercaseRoman)
{
if (!numberingOpened)
{
strHTML += "<ol type=\"i\">";
numberingOpened = true;
}
if (!numbLiOpened)
{
strHTML += "<li>";
numbLiOpened = true;
}
if (txtRange.Character == Convert.ToChar(13))
{
strHTML += "</li>";
numbLiOpened = false;
}
}
else
{
if (numberingOpened)
{
strHTML += "</ol>";
numberingOpened = false;
}
}
#endregion
#region bold
if (txtRange.CharacterFormat.Bold == FormatEffect.On)
{
if (!bOpened)
{
strHTML += "<b>";
bOpened = true;
}
}
else
{
if (bOpened)
{
strHTML += "</b>";
bOpened = false;
}
}
#endregion
#region italic
if (txtRange.CharacterFormat.Italic == FormatEffect.On)
{
if (!iOpened)
{
strHTML += "<i>";
iOpened = true;
}
}
else
{
if (iOpened)
{
strHTML += "</i>";
iOpened = false;
}
}
#endregion
#region underline
if (txtRange.CharacterFormat.Underline == UnderlineType.Single)
{
if (!uOpened)
{
strHTML += "<u>";
uOpened = true;
}
}
else
{
if (uOpened)
{
strHTML += "</u>";
uOpened = false;
}
}
#endregion
strHTML += txtRange.Character;
}
strHTML += "</span></html>";
return strHTML;
}
And I am yet to start the reverse conversion for html to rtf, once i done with that, i will post that answer too.
Hope this helps.
Thanks,
Noorul.