8

Is there a text editor on the web that supports input from RTF-formatted documents?

I know it is a bit of an odd request for webdev, but I need to read RTF documents from the database and edit them in a web-based text editor and store it back in RTF. Before I invest too heavily in a conversion tool, I thought I would ask if any of the many web text editors supported RTF. My research is showing that they don't.

Additionally, since this is an MVC 4.6 application, would it be a huge effort to write a two-way RTF-HTML conversion tool in C#?

Sample input that would be received by the editor: "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par }"

treeblah
  • 1,205
  • 2
  • 11
  • 26
  • Might I ask if you ever solved this issue? I have a similar use-case where I need to display and edit rtf data in a web component. – Unforgiven Dec 18 '22 at 15:54

3 Answers3

3

Quill is a rich text web editor.

Using the code from the quickstart you could enable it like this

Create the toolbar container

<div id="toolbar">
  <button class="ql-bold">Bold</button>
  <button class="ql-italic">Italic</button>
</div>

Create the editor container

<div id="editor">
  <div>Hello World!</div>
  <div>Some initial <b>bold</b> text</div>
  <div><br></div>
</div>

Include the Quill library

<script src="//cdn.quilljs.com/0.20.1/quill.js"></script>

Initialize Quill editor

<script>
  var quill = new Quill('#editor');
  quill.addModule('toolbar', { container: '#toolbar' });
</script>

Setting the editor text

editor.setText("RTF document ");

Getting the editor text

by default 0 will get everything in the editor

var text = editor.getText(0);

also see this Mozilla post which defines how to implement your own rich text editor.

Wamadahama
  • 1,489
  • 13
  • 19
  • 6
    Sorry if my post wasn't initially clear, but I mean rather than a rich-text editor, I need an editor that supports input from rich-text files. This means the input would be in a format like "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par }" rather than HTML. – treeblah Aug 17 '16 at 17:29
  • You are likely going to have to take the converting to HTML and putting in a html editor. https://code.msdn.microsoft.com/Converting-between-RTF-and-aaa02a6e. Looks like some effort, but I don't know if there anything out there that can do what your asking for. – Wamadahama Aug 17 '16 at 17:43
  • 1
    That link does look promising, even if it requires references to Windows.Controls. It's looking more and more like I'll have to write a custom tool to solve this. Thanks for the help. – treeblah Aug 17 '16 at 17:56
1

You could use Word to load the RTF file, then Save As HTML. Works but generates a pile of spurious MS- tags.

Or I've written a program (Visual Studio) that you can have if you want - it's a bit basic, doesn't deal with fonts, but converts most text formatting. Let me know if you're interested (I'd need to tidy it a bit - it's very old - a bit like me).

Though as I write this, I see that Wamadahama may have a better solution.

Tony Duffill
  • 277
  • 1
  • 5
  • But this all reminds me that I've also written a program that tidies Word HTML documents and brings them back to somewhere near normal. (Visual Studio again). – Tony Duffill Aug 17 '16 at 18:00
  • Sure, if you want to post the source I would be more than happy to take a look at it. It looks like I will be writing a custom converting tool so every bit helps! – treeblah Aug 17 '16 at 18:53
  • OK - let me refresh my memory about what they do and tidy them a bit. They are VS 2008 and both fairly basic in their output - I wrote them years ago for a specific project. I can't believe there isn't an RTF-HTM converter program out there by now. I'll get back to you with a download location. – Tony Duffill Aug 18 '16 at 15:09
  • Right - having tested these, I have to say that they are now so outdated they're not worth a hill of beans - much has changed in HTML since I wrote them (and maybe RTF too). As I say, Word will convert both ways (if you can put up with bloated files) and there also seem a lot of possibilities out there - Google 'convert rtf to htm'. Looking at my past efforts, it's a big call to write a custom converter (I was just dealing with known local output) - but when others have already done it?... – Tony Duffill Aug 18 '16 at 18:25
  • Yeah it's a big project, but unfortunately the open source offerings for RTF-HTML conversion aren't the greatest (my time to shine!). Thanks for taking a look though! – treeblah Aug 18 '16 at 18:37
0

I also cam to this point and solved it by converting the html to rtf with a npm package. Like i posted here How to convert HTML to RTF using JavaScript you can use the package created from npm html-to-rtf-browser and bundled to a single file like i describe here

javascript-html-to-rtf-browser

form.onsubmit = function () {
  // convert html to rtf
   var htmlContent = editorElement.html();
   var htmlToRtfLocal = new window.htmlToRtf();
   var rtfContent = htmlToRtfLocal.convertHtmlToRtf(htmlContent);
   editorElement.html(rtfContent);
   return true;
}

Where editorElement is the quill content element/editor as jQuery element and form is the parent form ( with jQuery $(editorElement).closest('form') ).

geraphl
  • 305
  • 4
  • 10