1

My web application has an feature wherein preformatted RTF documents are used as templates and the user can select the source of data and then merge with the RTF documents templates to create merged RTF files. The RTF templates have placeholders which get replaced with user selected content. The final doc can either be saved or opened directly if word/wordpad is available on the local users machine.

Now, I have a requirement to display the merged document to the user for confirmation. The user may either print or save the document to the system directly. The display should not be word/wordpad application but should be within the application itself, using textarea or something similar to render the document. Can you please let me know if its possible to render the RTF document in textarea or not. Along with the displayed content, there should be options to print and save the document.If I have to convert the RTF to Html and then display the html content in textarea , please let me know how i can do the conversion and then display the html in the page.

javauser
  • 91
  • 4
  • 11

2 Answers2

2

That's a very difficult requirement. First of all, let's dismiss the idea about a <textarea>, because it does not support any formatting at all. All the WYSIWYG editors you've seen out there are based on <iframe>s.

Secondly, no browser can directly display a RTF. You can embed it as an <object>, and some might show it (IE probably will), but I can't say which ones won't. Portable devices almost certainly won't. But you should test this though, maybe it works well enough after all.

Failing that, HTML conversion is also out of question, because RTF has very very many features that cannot be emulated in HTML. There are some converters out there (google), but but they will all come with serious limitations. If you want full support, you will have to do your own rendering via Canvas or Flash or something.

To this end I'd suggest checking out Google Docs. They've gone through all of this hassle and have a rather feature-full engine for displaying most possible documents. I think it was also possible to embed them in your own webapges, though I've never checked it out myself.

Vilx-
  • 104,512
  • 87
  • 279
  • 422
  • Hi, Thanks for your response. I tried google docs viewer as well as zoho viewer and they both seem to address my requirement somehow. But, I can't use them as the docs are private and moreover the client would not allow internet access from their application. So, can you or someone let me know on how I can write my own custom doc viewer application as a component and integrate it with my application. – javauser Feb 20 '12 at 12:07
  • 1
    As I said, it's extremely complicated. You'll have to parse the entire RTF yourself and draw it somehow. The [RTF spec](http://www.microsoft.com/download/en/details.aspx?displaylang=en&=tm&id=10725) alone is 278 pages long and has an insane amount of features. You could spend years trying to do this alone. I still advise seeking existing components that you can integrate in your products. There has to be something out there. – Vilx- Feb 20 '12 at 13:49
-1

Use a <PRE> tag to Display/Render RTF doc in browser.

Echilon
  • 10,064
  • 33
  • 131
  • 217
Nayab
  • 31
  • 3
  • This simply does not work.... Tested with
    and also tested using htmlentities to encode the RTF into proper HTML, all it does is display the raw source code of the RTF.
    – Ralph Ritoch Dec 31 '13 at 03:36