Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get plain text from an RTF text

Tags:

c#

.net

rtf

I have on my database a column that holds text in RTF format.

How can I get only the plain text of it, using C#?

Thanks :D

like image 683
rpf Avatar asked Feb 27 '09 17:02

rpf


People also ask

How do I convert RTF to plain text?

Convert the RTF file to a text file using a word processor. To do this, first open the file in a program such as Microsoft Word or OpenOffice Writer. Select the “Save as” command in the File menu, choose the TXT format in the drop-down menu and click “Save.”

Can I convert RTF to word?

Find a desired location to save the file. From within the Save As Window, find the Save File Type field. Select the drop-down arrow, and change the file from Rich Text Format (rtf) to Word Document (doc). Select Save.

Is RTF same as plain text?

What is an RTF File. This is a cross-platform document file format with better text adjustability than plain text files. This file format allows the user to perform several formatting tasks, such as font sizes and colors, bolding, italics, and others.


1 Answers

Microsoft provides an example where they basically stick the rtf text in a RichTextBox and then read the .Text property... it feels somewhat kludgy, but it works.

static public string ConvertToText(string rtf)
{
   using(RichTextBox rtb = new RichTextBox())
   {
       rtb.Rtf = rtf;
       return rtb.Text;
   }
}
like image 132
Daniel LeCheminant Avatar answered Oct 02 '22 16:10

Daniel LeCheminant