Good day.
I'm checking the Spire.Doc to convert html to rtf and then save the rtf string into database to be used by report generation application.
I tried saving the rtf to a file and when I opened the file it shows the expected results.
However, when I tried to get the rtf string and save to db and then get the rtf from db and then render it is not the same as the one saved to a file.
Is there a function to get the rtf string (not the text)?
Please advise on how to properly save the rtf to db without losing the rtf format.
Below is the code snippet.
Refer to attached files for the html, saved rtf and rtf saved to db.
Thank you.
- Code: Select all
string html = model.InfoHtml; //from html rich text editor
using (MemoryStream inputStream = new MemoryStream())
{
StreamWriter writer = new StreamWriter(inputStream);
writer.Write(html);
writer.Flush();
using (Document doc = new Document())
{
doc.LoadFromStream(inputStream, FileFormat.Html, Spire.Doc.Documents.XHTMLValidationType.None);
doc.SaveToFile(rtfFilename, FileFormat.Rtf);
using (MemoryStream outputStream = new MemoryStream())
{
doc.SaveToStream(outputStream, FileFormat.Rtf);
model.InfoRtf = Encoding.UTF8.GetString(outputStream.GetBuffer(), 0, (int)outputStream.Length);
outputStream.Close();
outputStream.Dispose();
}
doc.Close();
doc.Dispose();
}
writer.Close();
writer.Dispose();
inputStream.Close();
inputStream.Dispose();
}