Could anyone please help me to create RTF from string in C#?
I save all the formats (bold, italic, etc) in a customized class.
Jerry
I know i'm NECRO an old question but, anyways, here is my apport:
//This Instances a new RichTextBox Control and uses it so save the Text
private void Save_RTF_file(string pFilePath, string pRTFText)
{
try
{
using (RichTextBox RTB = new RichTextBox())
{
RTB.Rtf = pRTFText;
RTB.SaveFile(pFilePath, RichTextBoxStreamType.RichText);
}
}
catch (Exception ex)
{
throw ex;
}
}
Now you pass a file_path and the RTF formatted Text:
//This is a simple 1 line 'Hello World' RTF text
string RTF = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang14346{\fonttbl{\f0\fnil\fcharset0 Calibri;}} {\*\generator Riched20 10.0.10586}\viewkind4\uc1 \pard\sa200\sl276\slmult1\f0\fs22\lang10 Hello World.\par }";
Save_RTF_file(@"C:\temp\my_rtf_file.rtf"), RTF);
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With