如何转换的FlowDocument到rtf [英] How to convert FlowDocument to rtf

查看:283
本文介绍了如何转换的FlowDocument到rtf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个WPF的RichTextBox从中节省的FlowDocument作为数据库的byte []。现在我需要在一份报告中的RichTextBox为RTF检索这些数据并显示。
当我尝试字节使用的TextRange或XAMLReader我得到的FlowDocument回来,但我如何将其转换为RTF格式字符串作为该报告的RichTextBox只需要RTF []转换。

I have used a WPF RichTextBox to save a flowdocument from it as byte[] in database. Now i need to retrieve this data and display in a report RichTextBox as an rtf. when i try to convert the byte[] using TextRange or in XAMLReader i get a FlowDocument back but how do i convert it to rtf string as the report RichTextBox only takes rtf.

感谢

阿文德

推荐答案

您不应该坚持直接的FlowDocument的,它应被视为该文件的运行时表示,没有实际的文档内容。相反,使用 TextRange类保存和加载各种格式,包括的 RTF

You should not persist the FlowDocument directly as it should be considered the runtime representation of the document, not the actual document content. Instead, use the TextRange class to Save and Load to various formats including Rtf.

一个快速出样关于如何创建一个选择并保存到流:

A quick sample on how to create a selection and save to a stream:

var content = new TextRange(doc.ContentStart, doc.ContentEnd);

if (content.CanSave(DataFormats.Rtf))
{
    using (var stream = new MemoryStream())
    {
        content.Save(stream, DataFormats.Rtf);
    }
}

要加载的内容为一个选区有异曲同工之处:

To load content into a selection would be similar:

var content = new TextRange(doc.ContentStart, doc.ContentEnd);

if (content.CanLoad(DataFormats.Rtf))
{
    content.Load(stream, DataFormats.Rtf);
}

这篇关于如何转换的FlowDocument到rtf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆