tags:

views:

4857

answers:

8

Are there any libraries around that can convert Rtf to HTML. We have a crystal report that we need to send out as an e-mail, but the HTML generated from the crystal report is pretty much just plain ugly and causes issues with some e-mail clients. I wanted to export it as rich text and convert that to HTML if it's possible.

Any suggestions?

A: 

I am not aware of any libraries to do this (but I am sure there are many that can) but if you can already create HTML from the crystal report why not use XSLT to clean up the markup?

Andrew Hare
A: 

I think you can load it in a Word document object by using .NET office programmability support and Visual Studio tools for office.

And then use the document instance to re-save as an HTML document.

I am not sure how but I believe it is possible entirely in .NET without any 3rd party library.

chakrit
Word? He's trying to *get rid* of the bad markup! ;)
Daniel Schaffer
oh i forgot that... but that should gives some control over the result markup no?
chakrit
By just effectively exporting it from word? I haven't use office automation in like... 3 versions ... but that said, I doubt it.
Daniel Schaffer
I mean you could *edit* the word document before exporting it... like removing certain kind of elements etc.
chakrit
A: 

You can try to upload it to google docs, and download it as HTML.

stiduck
+1  A: 

If you don't mind getting your hands dirty, it isn't that difficult to write an RTF to HTML converter.

Writing a general purpose RTF->HTML converter would be somewhat complicated because you would need to deal with hundreds of RTF verbs. However, in your case you are only dealing with those verbs used specifically by Crystal Reports. I'll bet the standard RTF coding generated by Crystal doesn't vary much from report to report.

I wrote an RTF to HTML converter in C++, but it only deals with basic formatting like fonts, paragraph alignments, etc. My translator basically strips out any specialized formatting that it isn't prepared to deal with. It took about 400 lines of C++. It basically scans the text for RTF tags and replaces them with equivalent HTML tags. RTF tags that aren't in my list are simply stripped out. A regex function is really helpful when writing such a converter.

Kluge
Why bother converting from RTF->HMTL if he already is converting Report->HTML? He should skip RTF altogether as it is not needed.
Andrew Hare
A: 

In codeproject you may find some interesting articles w.r.t rtf converters and alike:
http://www.codeproject.com/info/search.aspx?artkw=rtf&sbo=kw
Hope this helps.

Jaime Febres
+1  A: 

Mike Stall posted the code for one he wrote in c# here :

http://blogs.msdn.com/jmstall/archive/2006/10/20/rtf_5F00_html.aspx

rizzle
This one almost worked. I could have added the things I needed, but it wasn't worth the effort.
Aaron Smith
+5  A: 

I would check out this tool on CodeProject RTFConverter. This guy gives a great breakdown of how the program works along with details of the conversion.

Writing Your Own RTF Converter

Richard R
Thanks a lot. This was useful. Hopefully this will fix the issues we were having. It just came up again today, perfect timing. :-)
Aaron Smith
A: 

This is .Net library to convert RTF to HTML, created completely in C# and has own RTF parser and it HTML writer.

  • You may choose HTML 3.2, HTML 4.01 or XHTML as output
  • Supports full RTF to HTML converting in memory even with images
  • Works in .Net 1.1, 2.0, 3.0, 3.5 and 4.0
  • Absolutely standalone
  • Works in shared-hosting with medium trust level, like a Godaddy

Some samples in C#:

1# convert rtf string to html string

SautinSoft.RtfToHtml.Converter r = new SautinSoft.RtfToHtml.Converter();
string rtf = @"{\rtf {\b bold text {\i bold + italic}} and plan text}";
string html = r.ConvertString(rtf);

2# convert rtf file to html file

SautinSoft.RtfToHtml.Converter r = new SautinSoft.RtfToHtml.Converter();
r.ImageStyle.ImageFolder = @"d:\my webs";
r.ImageStyle.ImageSubFolder = "images";
r.ImageStyle.IncludeImageInHtml = false;
r.ConvertFile(@"d:\test.rtf", @"d:\test.html");
Maximus