|
can you please share the code of converting rtf to html in vb.net
|
|
|
|
|
The code didn't work for me in VS2010, it created individual html statements for every single character when using a very simple set of basic strings. The problem was here:
If _rtfSource.SelectionBackColor <> clrBackColor Then
This would show true for every single character. So, by changing it to:
If _rtfSource.SelectionBackColor.ToArgb <> clrBackColor.ToArgb Then
It made the statement false, thus, the html output was fine. I have no clue why VS2010,.NET4 was showing them as not equal, I even put in a messabox to show the string values and they showed equal in the messagebox's, but for some reason, the color's were different themselves. Could be a bug in VS or .NET, I'm not sure. Either way, if someone else is having the same problem, this fixed it for me, I'm going to test out using different colors, and other fonts next. I'll make another post if something else is broken. Thanks again for this, it's very solid.
|
|
|
|
|
Wow this works! I did wonder if it could possibly be correct that the OP wanted to tag each letter. This solves it. Thanks so much!
|
|
|
|
|
Good job! But it does parse the first character and line improperly, at least for me.
It will keep the first char on the top line but the rest of the text and/or sentence is put on a new line below the first char.
Example:
This is a sentence.
OK, Now this is how its rendering...
T
his is a sentence
Maybe a minor update to fix this or if you could tell me what to do. Either way thanks for the library
Edit: Maybe update to properly convert the links in the richtextbox to html links?
|
|
|
|
|
I'll be releasing a new version of this control soon that's a little more friendly and easier to use and uses some of the new features of the .net4 namespaces. I'll link it up here in the comments when I'm done. Most of the bugs and suggestions I've gotten have been fixed and or added since this initial version came out.
I'll be making sure that this bug is not included in the next release.
Other features that will be added are...
1. Underline support
2. Link support
3. Image support
4. Direct File IO to write to a file instead of just returning a string.
If anyone has any other features they'd like added let me know.
|
|
|
|
|
Sounds good! If you would happen to have a Beta or something I would be happy to use it. Just give me a download link or something. Thanks
Jason
|
|
|
|
|
Very nice code. I'm kinda giving a bump to the op's last post. Do you have any kind of link to a beta of your new release? I'm really liking the class and want to use it for a lot of applications. The image code would be nice, but it's not necessary for my needs, so if you have any kind of update, that would be awesome. Very nice contribution btw, I'm personally very impressed with your work on this. Thank you again for your hard work and your contribution to the community. I know how hard it is to contribute opensource and then have to manage it, so, I wanted to thank you again for that as well. Any update is appreciated, I'm sure everyone here is looking forward to it, thanks,
|
|
|
|
|
Hi This is the best rtf to HTML code I have found so far I use it a lot but would really like the image's to be added
Did you ever do any more work on this ?
Steve
|
|
|
|
|
Hi All,
I have a question.
I am typing some text in textbox or richtextbox in vb.net(2003 version) and on the button click event i want a html file (its good if the output is in marquee format) to be created in a desired location which contains the text written in textbox or richtextbox.
Please can anyone helpme out!!
|
|
|
|
|
Hi.I used this code but how can I use with Underline tag?
Please help me on this.
Thank you.
|
|
|
|
|
Hi, I combined your code with the RTBEx code found on the MSDN site. This generates a Rich Text Box control that has .System.Drawing functionality, which can be used to print the RTB contents.
So now with your code added, the Rich Text Box Control will also have an .HTML function which will return the HTML string.
I want to know if it’s ok that I post this and reference this to your page or would you like to post this? I'm sure other people will find it helpful.
Marco
|
|
|
|
|
Post whatever you like I'd also like to see your modifications. Just post some sort of linkback if you use code.
|
|
|
|
|
pls cn i have the reference and the post ls
|
|
|
|
|
Hi,
thanks for your great Example. I don't know, how I change the Font and the FontSize for the selected. Can you post the code for them, please.
thank you
gredds
|
|
|
|
|
|
I Really Like your code.
I have made some modifications to your code as per your permissions granted. These Modifications include adding spaces so the converted HTML is spaced exactly like the RTF is spaced. I discovered that after converting and placing in a HTML document it was all Left aligned. I also found that when copying the RTF from VB IDE that if the VB code referenced HTML formatting that it used the references to HTML. So I made a modification to prevent this. I am at present looking into a way to change the embedded objects to their respective Image or Thumb nails. The only way I could get this to post the code correctly Was to unchecked "Use HTML in post" and unchecked Encode. Because it caused the HTML code " " to change to a " ". Wrapping it did nothing to help.
But here is the code the way it is modified starting from Alignment Which was not modified.
<pre>
'Alignment
If intPos = 0 Then
strReturn &= "<p style=""text-align:" & _rtfSource.SelectionAlignment.ToString & """>" '
altCurrent = _rtfSource.SelectionAlignment
Else
If _rtfSource.SelectionAlignment <> altCurrent Then
strReturn &= "</p>"
strReturn &= "<p style=""text-align:" & _rtfSource.SelectionAlignment.ToString & """>"
altCurrent = _rtfSource.SelectionAlignment
End If
End If
'" (1) Modified to allow spaces and Html control syntex to be displayed(Curtis Underwood,April/29/2010 )
If intPos > 1 Then
If _rtfSource.Text.Substring(intPos, 1) = CStr(Chr(60)) And _rtfSource.Text.Substring(intPos - 1, 1) = CStr(Chr(34)) Then
strReturn &= "<"
intPos += 1
Do Until _rtfSource.Text.Substring(intPos, 1) = CStr(Chr(34)) Or _rtfSource.Text.Substring(intPos, 1) = CStr(Chr(62))
strReturn &= _rtfSource.Text.Substring(intPos, 1)
intPos += 1
Loop
End If
ElseIf intPos < _rtfSource.Text.Length Then
If _rtfSource.Text.Substring(intPos, 1) = CStr(Chr(62)) And _rtfSource.Text.Substring(intPos + 1, 1) = CStr(Chr(34)) Then
strReturn &= ">"
End If
End If
If _rtfSource.Text.Substring(intPos, 1) = " " Then
strReturn &= " "
Else
strReturn &= _rtfSource.Text.Substring(intPos, 1)
End If
Next</pre>
|
|
|
|
|
|
Hi, this is a really nice and helpful article.
Is there any specific code to convert from HTML to richtext ? I currently have a richtextbox where i need to show the html content from a HTML-page.
|
|
|
|
|
I found a little bug:incorrect HTML
<div><SPAN STYLE="COLOR:#E01301"><span style="background-color:window"><span style="font:normal normal normal 9pt/normal Courier New"><p style="text-align:Left">P</span><span style="background-color:window">e</span><span style="background-color:window">n</span><span style="background-color:window">g</span><span style="background-color:window">u</span><span style="background-color:window">i</span><span style="background-color:window">n</span><span style="color:black"></span><span style="background-color:window">!</span></span></SPAN></p></div>
1.It translates letter by letter
2.<span ....><span....>ABC</span></span> -not correct , The first letter looks like the first in RTF, but others-Times New Roman,12
<span .... ....>ABC</span> -correct
|
|
|
|
|
I found the same problem. To fix it I moved the two lines "clrBackColor = _rtfSource.SelectionBackColor" to before the colors are converted to html color. The conversion some how changes it from "WindowColor" as it is first read to "White". (vb 2008 at least)
|
|
|
|
|
dear , can you tell me exactly what i must do to save the problem?
|
|
|
|
|
I don't have the code here and can't download it here. I'll try to remember to post in the next few days. There were only to places it needed to be changed. If you search for:
clrBackColor = _rtfSource.SelectionBackColor
Cut it and then look look for the sub/function call just a few (one or two I think) lines before it and paste it. Still I'll try to post the part I'm talking about later in case you still cannot find it.
|
|
|
|
|
Hello,
can you send me the changed QC via Mail? chefkoch@djbepy.de THX
|
|
|
|
|
'Background color
If intPos = 0 Then
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
clrBackColor = _rtfSource.SelectionBackColor
Else
'If _rtfSource.SelectionBackColor <> clrBackColor Then
If _rtfSource.SelectionBackColor.A <> clrBackColor.A _
Or _rtfSource.SelectionBackColor.R <> clrBackColor.R _
Or _rtfSource.SelectionBackColor.G <> clrBackColor.G _
Or _rtfSource.SelectionBackColor.B <> clrBackColor.B Then
strReturn &= "</span>"
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
clrBackColor = _rtfSource.SelectionBackColor
End If
End If
|
|
|
|
|
I totally forgot about this until I got an email on it about this post. So here is the original code.
'Background color
If intPos = 0 Then
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
clrBackColor = _rtfSource.SelectionBackColor '<-Originally Here
Else
If _rtfSource.SelectionBackColor <> clrBackColor Then
strReturn &= "</span>"
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
clrBackColor = _rtfSource.SelectionBackColor '<-Originally Here
End If
End If
And then what fixed it for me was simply.
'Background color
If intPos = 0 Then
clrBackColor = _rtfSource.SelectionBackColor '<-Moved Here
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
Else
If _rtfSource.SelectionBackColor <> clrBackColor Then
clrBackColor = _rtfSource.SelectionBackColor '<-Moved Here
strReturn &= "</span>"
strReturn &= "<span style=""background-color:" & HtmlColorFromColor(_rtfSource.SelectionBackColor) & """>"
End If
End If
|
|
|
|