RTF formatting.

Asked

Viewed 55 times

0

I have an RTF in the database that saves colors, enter, among other actions that the user gave. I am using the following code to convert the RTF to show in HTML, however I am losing all these formatting, there is some way to fix it?

    public static string rtfToTxt(this string txtRtf) {
        using(var generalRTF = new System.Windows.Forms.RichTextBox()) {
            if(txtRtf.Length > 5 && txtRtf.Substring(0, 5).Equals("{\\rtf")) {
                try {
                    generalRTF.Rtf = txtRtf;
                    return generalRTF.Text;
                } catch(ArgumentException) {
                    return txtRtf;
                }
            } else {
                return txtRtf;
            }
        }
    }

An example would be this RTF:

 {\rtf1\ansi\ansicpg1252\deff0\deflang1046{\fonttbl{\f0\fnil\fcharset0 Verdana;}{\f1\fswiss\fcharset0 Arial;}}  {\colortbl ;\red255\green0\blue0;}  \viewkind4\uc1\pard\f0\fs17 ENTER  \par   \par \cf1\b\f1\fs22 Letra Colorida\cf0\b0\f0\fs17   \par }  

Where I would have a enter and a colored letter and I end up losing these formatting.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.