-1

我正在开发一个 WPF 报告应用程序。

我的报告构造为 WPF 控件(FlowDocument 或 FixedDocument)并包含表格。我想将其保存为 XPS 并保留其结构(这意味着我可以将表格复制为表格,而不是像本文中解释的纯文本)。我找到了一种使用 XpsDocumentWriter 或 XpsSerializationManager 保存 WPF 控件的方法,但结果没有结构或轮廓。

是否可以将 WPF Control 保存为 Xps 以保留其结构?

4

2 回答 2

1

似乎没有办法在使用XpsDocumentWriteror序列化它时保留 WPF 元素语义XpsSerializationManager

构造具有结构的文档的唯一方法是使用命名空间中的低级 API System.Windows.Xps.Packaging,如本文所述。使用此 API,您可以获得XmlWriter用于构建FixedPage内容

XpsDocument document = new XpsDocument(destFileName,FileAccess.ReadWrite); 
IXpsFixedDocumentSequenceWriter docSeqWriter = document.AddFixedDocumentSequence(); 
IXpsFixedDocumentWriter docWriter = docSeqWriter.AddFixedDocument(); 
IXpsFixedPageWriter pageWriter = docWriter.AddFixedPage();
XmlWriter xmlWriter = pageWriter.XmlWriter;

和一个Stream用于编写文档结构的

XpsResource storyFraments = pageWriter.AddStoryFragment();
Stream stream = storyFraments.GetStream();

尽管命名空间中有System.Windows.Documents.DocumentStructures代表StoryFragments元素的类及其子元素,但在写入资源流时不能使用它们。

于 2015-01-29T10:57:17.057 回答
1

XPS 是一种固定文档格式,WPF 允许您将 FlowDocument 保存为 FixedDocument 作为 XPS 文件,当您想添加更多功能时需要代码,您可以按照本文进一步了解。

将 XAML 流文档转换为带有样式的 XPS(多页、页面大小、页眉、边距)

于 2015-01-28T13:36:11.527 回答