Issue: Code is not saving the flowdocument to RTF.
I am using FlowDocumentScrollViewer. Inside this I have a FlowDocument.
In .cs file, I have a grid.
Grid g = new Grid();
Then Dynamically creating Grid.ColumnDefinitions and RowDefinitions.
Finally adding grid g to Flowdocument like follows.
flowDocument.Blocks.Add(new BlockUIContainer(g));
This is working fine for previewing and printing using XpsDocumentWriter.
My problem is with saving this flowDocument to RTF file. I am giving FlowDocumentScrollViewer object and filename to the function like follows.
public static void CreateRTF(FlowDocumentScrollViewer flowDocumentReader, string fileName)
{
string copyString = XamlWriter.Save(flowDocumentReader.Document);
FlowDocument doc = XamlReader.Parse(copyString) as FlowDocument;
using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
{
//TextRange textRange = new TextRange(doc.ContentStart, doc.ContentEnd);
//textRange.Save(fs, DataFormats.Rtf);
var content = new TextRange(doc.ContentStart, doc.ContentEnd);
if (content.CanSave(DataFormats.Rtf))
{
using (var stream = new MemoryStream())
{
content.Save(stream, DataFormats.Rtf);
}
}
}
}
Issue is: When I am running this, I am getting only empty file.
I appreciate all your helps.
Binu