locked
RichText(RTF) or HTML RRS feed

  • Question

  •  

    I am building a system that has a farily complex note system.  I want the user to be able to enter good notes with a rich text experance.  The system is primarily a win forms app however I know that there will have to be a web app built later, the windows form will always be the primary interface but asp.net will be used later.  Should I use RTF or HTML I know that there are rft viewers for html but I have never used any.  I also have never used a tool that you can create html from a windows form app.

     

    I am pretty good at rtf, I have written a few apps that use it and I understand the sintax, of course I am much better at writing html I am not sure.  We have a large team of web designers that use the system as well althought they are not the primary users.

     

    Anybody have any recomendations on tools or techniques here I would be quite grateful.

     

    Justin

    Thursday, September 20, 2007 5:19 PM

Answers

  • Do the app's [win/web] also show the notes?

    I think RTF is'nt that easy to show on the web...

    When you also need to show things I would go for a more general data format [XML ] and use for the formating some XSLT.

    Saturday, September 29, 2007 5:23 AM
  • I've found that RTF editors are just generally "better" than HTML ones, and seem to hook into things like spell checking more seamlessly. Since the primary interface is a win forms app., I'd say go with that. You can render the RTF as HTML later for a web app later, if it's necessary.

     

    Thursday, October 4, 2007 8:32 PM
  • Hi Justin,

    Since this is an Architecture forum I think it's probably best to think about strategies rather than implementation.

     

    Your project is basically an application whose general functionality will be the same regardless of deployment however there will be some differences in certain scenarios.

     

    e.g. your application will always allow users to enter/edit notes and provide some form of saving/loading ability.  Depending on deployment some features may not be available - someone mentioned that page breaks are not available under HTML.  So for the Page Breaks feature I would make this an optional feature that must be enabled/disabled depending on deployment.

     

    This hints that you should develop your application using the implementation/proxy design pattern. The implementation for RTF would allow Page Breaks and HTML would not.

     

    An even better approach is to abstract your application from the resulting output format entirely.  This allows for maximum flexibility.  e.g. Image manipulation programs such as Adobe Photoshop or spreadsheet programs such as MS Excel do not have a custom editor once the data is loaded.  i.e. if you load a BMP, TIFF or JPG into Photoshop the UI remains the same.  The is true for Excel regardless of whether you load a CSV or XLS file.

     

    It is only when you go to save the data should it be transformed from a higher-level format to a specific format.  Of course this would mean that in the case of your application you would need to display a warning 'Some items can not be converted' during a HTML save (page breaks).  This is similar when saving a Word 2007 document to say Word 97 format.

    Sunday, December 23, 2007 1:37 PM

All replies

  • Hi Justin,

    I believe you should determine the content format from a purist view - based on the features you would want your document to support. Once you have that - and if you find that both HTML and RTF support it - you shouldnt care too much as there are libraries available to convert one to the other.

     

    Its easy to find browser based HTML editors like the one on this forum. They could be pure javascript editors like TinyMCE, FCKEditor etc. and can offer a lot of functionality.

    However, HTML lacks things like Page breaks, hyphenation and justification etc. If those are your needs - you just cant have them till you code your own Activex / Flash widgets for the same.

     

    I havent tried HTML editing from Winforms myself but I believe that you will find controls easily.
    Tuesday, September 25, 2007 2:03 PM
  • I am leaning towards RTF since it is primarily a windows form system with only certain aspects being ported to the web at a later date.  I am still undecided, it is a pretty close race because my needs are really simple.  Not much else needed that what this forum has.  I am basing my system off of TFS so I think that I will use rtf because of its simplicity for windows forms.  I know I can find a rtf parcer for asp.net so I am not really that worried about it.

     

    Thanks for the help.

    Justin

    Tuesday, September 25, 2007 2:15 PM
  • Do the app's [win/web] also show the notes?

    I think RTF is'nt that easy to show on the web...

    When you also need to show things I would go for a more general data format [XML ] and use for the formating some XSLT.

    Saturday, September 29, 2007 5:23 AM
  • I've found that RTF editors are just generally "better" than HTML ones, and seem to hook into things like spell checking more seamlessly. Since the primary interface is a win forms app., I'd say go with that. You can render the RTF as HTML later for a web app later, if it's necessary.

     

    Thursday, October 4, 2007 8:32 PM
  • Hello,

    I have same problem. In our application user edit text with richtextboxes in client application. The formatted text will be used on client, exported to other format (pdf) and will be displayed on web pages (with formating included).

     

    Using rtf is in windows client easier, but on the other hand html is much more useful on the web and also smaller to save to database (recent requirement is only use only bold, underline and italic to formating the text).

     

    I spent some time in searching for rtf2html converter, but founded products are commercial or their have problems with czech language (doesnt work with other code pages..).

     

    Any idea what is more used? And why?

    Thank you.

    Tuesday, October 9, 2007 6:39 AM
  • hi .

    At your post you wrote that there are libraries that aloww you to convert from html to rtf.

    i desperetly looking for such a library but tho only one i found were expensive commercial library.(239$min)

     

    if you know about a way to convert from html ti rtf and from html to rtf (maybe with part of the tinymce script) i would really

    be glad to know.

     

     

    thank

     

    ori

    Saturday, December 15, 2007 2:30 PM
  • Hi Justin,

    Since this is an Architecture forum I think it's probably best to think about strategies rather than implementation.

     

    Your project is basically an application whose general functionality will be the same regardless of deployment however there will be some differences in certain scenarios.

     

    e.g. your application will always allow users to enter/edit notes and provide some form of saving/loading ability.  Depending on deployment some features may not be available - someone mentioned that page breaks are not available under HTML.  So for the Page Breaks feature I would make this an optional feature that must be enabled/disabled depending on deployment.

     

    This hints that you should develop your application using the implementation/proxy design pattern. The implementation for RTF would allow Page Breaks and HTML would not.

     

    An even better approach is to abstract your application from the resulting output format entirely.  This allows for maximum flexibility.  e.g. Image manipulation programs such as Adobe Photoshop or spreadsheet programs such as MS Excel do not have a custom editor once the data is loaded.  i.e. if you load a BMP, TIFF or JPG into Photoshop the UI remains the same.  The is true for Excel regardless of whether you load a CSV or XLS file.

     

    It is only when you go to save the data should it be transformed from a higher-level format to a specific format.  Of course this would mean that in the case of your application you would need to display a warning 'Some items can not be converted' during a HTML save (page breaks).  This is similar when saving a Word 2007 document to say Word 97 format.

    Sunday, December 23, 2007 1:37 PM
  •  

    Hi

      I need to convert richtextbox content(RTF data) into HTML string . I am using Richtextbox Control for the purpose of mailing in our application. As we can not set richtext foramat as the mail body for MailMessage. I need to this using c# in windows application.

     

       Can you please help me out.

    Thanks in Advance

     

        

    Monday, February 18, 2008 1:52 PM
  • The following class work for me, i found it in this forum

     
    /// <summary> 
        /// An object that converts RTF to HTML 
        /// </summary> 
        /// <remarks> 
        ///   Completed: 11/02/2006 
        ///   Author: George H. Slaterpryce III 
        ///   Modifications: none 
        ///   ************************************************************************* 
        ///   ************************************************************************* 
        ///   License: This code is free to use in private or commercial  
        ///   applications, re-distribution of this code is allowed in whole  
        ///   or in part so long as this header remains intact. All modifications  
        ///   and further development to this code should be indicated by adding the  
        ///   name of the author and the modifications/improvements under the  
        ///   "Modifications:" section. 
        ///   Modification Listings should be in the format of. 
        ///   (#) Description of modification (Name, Date) 
        ///   ************************************************************************* 
        ///   ************************************************************************* 
        /// </remarks> 
        public class RTFtoHTML 
        { 
            #region "Private Members" 
     
            // A RichTextBox control to use to help with parsing. 
            private System.Windows.Forms.RichTextBox _rtfSource = new System.Windows.Forms.RichTextBox(); 
            #endregion 
            #region "Read/Write Properties" 
     
            /// <summary> 
            /// Returns/Sets The RTF formatted text to parse 
            /// </summary> 
            public string rtf 
            { 
                get { return _rtfSource.Rtf; } 
                set { if (value != null)_rtfSource.Rtf = value; } 
            } 
            #endregion 
            #region "ReadOnly Properties" 
     
            /// <summary> 
            /// Returns the HTML code for the provided RTF 
            /// </summary> 
            public string html 
            { 
                get { return GetHtml(); } 
            } 
            #endregion 
            #region "Private Functions" 
     
            /// <summary> 
            /// Returns an HTML Formated Color string for the style from a system.drawing.color 
            /// </summary> 
            /// <param name="clr">The color you wish to convert</param> 
            private string HtmlColorFromColor(System.Drawing.Color clr) 
            { 
                string strReturn = ""
                if (clr.IsNamedColor) 
                { 
                    strReturn = clr.Name.ToLower(); 
                } 
                else 
                { 
                    strReturn = clr.Name; 
                    if (strReturn.Length > 6) 
                    { 
                        strReturn = strReturn.Substring(strReturn.Length - 6, 6); 
                    } 
                    strReturn = "#" + strReturn; 
                } 
                return strReturn; 
            } 
     
            /// <summary> 
            /// Provides the font style per given font 
            /// </summary> 
            /// <param name="fnt">The font you wish to convert</param> 
            private string HtmlFontStyleFromFont(System.Drawing.Font fnt) 
            { 
                string strReturn = ""
                //style 
                if (fnt.Italic) 
                { 
                    strReturn += "italic "
                } 
                else 
                { 
                    strReturn += "normal "
                } 
                //variant 
                strReturn += "normal "
                //weight 
                if (fnt.Bold) 
                { 
                    strReturn += "bold "
                } 
                else 
                { 
                    strReturn += "normal "
                } 
                //size 
                strReturn += fnt.SizeInPoints + "pt/normal "
                //family 
                strReturn += fnt.FontFamily.Name; 
                return strReturn; 
            } 
     
            /// <summary> 
            /// Parses the given rich text and returns the html. 
            /// </summary> 
            public string GetHtml() 
            { 
                string strReturn = "<div>"
                System.Drawing.Color clrForeColor = Color.Black; 
                System.Drawing.Color clrBackColor = Color.Black; 
                System.Drawing.Font fntCurrentFont = _rtfSource.Font; 
                System.Windows.Forms.HorizontalAlignment altCurrent = HorizontalAlignment.Left; 
                int intPos = 0; 
                for (intPos = 0; intPos <= _rtfSource.Text.Length - 1; intPos++) 
                { 
                    _rtfSource.Select(intPos, 1); 
                    //Forecolor 
                    if (intPos == 0) 
                    { 
                        strReturn += "<span style=\"color:" + HtmlColorFromColor(_rtfSource.SelectionColor) + "\">"
                        clrForeColor = _rtfSource.SelectionColor; 
                    } 
                    else 
                    { 
                        if (_rtfSource.SelectionColor != clrForeColor) 
                        { 
                            strReturn += "</span>"
                            strReturn += "<span style=\"color:" + HtmlColorFromColor(_rtfSource.SelectionColor) + "\">"
                            clrForeColor = _rtfSource.SelectionColor; 
                        } 
                    } 
                    //Background color 
                    if (intPos == 0) 
                    { 
                        strReturn += "<span style=\"background-color:" + HtmlColorFromColor(_rtfSource.SelectionBackColor) + "\">"
                        clrBackColor = _rtfSource.SelectionBackColor; 
                    } 
                    else 
                    { 
                        if (_rtfSource.SelectionBackColor != clrBackColor) 
                        { 
                            strReturn += "</span>"
                            strReturn += "<span style=\"background-color:" + HtmlColorFromColor(_rtfSource.SelectionBackColor) + "\">"
                            clrBackColor = _rtfSource.SelectionBackColor; 
                        } 
                    } 
                    //Font 
                    if (intPos == 0) 
                    { 
                        strReturn += "<span style=\"font:" + HtmlFontStyleFromFont(_rtfSource.SelectionFont) + "\">"
                        fntCurrentFont = _rtfSource.SelectionFont; 
                    } 
                    else 
                    { 
                        if (_rtfSource.SelectionFont.GetHashCode() != fntCurrentFont.GetHashCode()) 
                        { 
                            strReturn += "</span>"
                            strReturn += "<span style=\"font:" + HtmlFontStyleFromFont(_rtfSource.SelectionFont) + "\">"
                            fntCurrentFont = _rtfSource.SelectionFont; 
                        } 
                    } 
                    //Alignment 
                    if (intPos == 0) 
                    { 
                        strReturn += "<p style=\"text-align:" + _rtfSource.SelectionAlignment.ToString() + "\">"
                        altCurrent = _rtfSource.SelectionAlignment; 
                    } 
                    else 
                    { 
                        if (_rtfSource.SelectionAlignment != altCurrent) 
                        { 
                            strReturn += "</p>"
                            strReturn += "<p style=\"text-align:" + _rtfSource.SelectionAlignment.ToString() + "\">"
                            altCurrent = _rtfSource.SelectionAlignment; 
                        } 
                    } 
                    strReturn += _rtfSource.Text.Substring(intPos, 1); 
                } 
                //close all the spans 
                strReturn += "</span>"
                strReturn += "</span>"
                strReturn += "</span>"
                strReturn += "</p>"
                strReturn += "</div>"
                strReturn = strReturn.Replace(Convert.ToChar(10).ToString(), "<br />"); 
                return strReturn; 
            } 
            #endregion 
     
        } 

    annamalai
    Friday, March 13, 2009 11:35 AM