c# - 从 FixedDocumentSequence 中获取 FixedDocuments

标签 c# .net xps

相当简单:

我有一个从磁盘中提取的 XPSDocument。我想从这个 XpsDocument 中获取 FixedDocuments,但我遇到了一些问题,因为我只能获取 FixedDocumentSequence,而且我不知道如何从这个序列中提取 XpsDocuments。

到目前为止,我已经尝试过类似的方法:

FixedDocument doc = (FixedDocument)myFixedDocSequence.References.First();   

该类型转换不起作用,但它说明了我正在努力实现的目标。

最佳答案

myFixedDocSequence.References.First(); 应该返回一个 DocumentReference。您是否尝试过使用 DocumentReference.GetDocument method 而不是类型转换, 它返回一个 FixedDocument?代码如下所示:

DocumentReference docReference = myFixedDocSequence.References.First();
FixedDocument doc = docReference.GetDocument(false);

阅读上面链接的文档,了解有关 GetDocument 参数选项的更多信息。此外,除非您确定 References.First() 不会为 null,否则请考虑使用 FirstOrDefault() 并在使用返回的对象之前检查是否为 null。

关于c# - 从 FixedDocumentSequence 中获取 FixedDocuments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3015699/

相关文章:

c# - ResourceDictionary WPF 样式中的交互触发器

c# - String.Format() 问题

c# - 我需要锁吗?

c# - C# WPF项目正确添加样式资源文件

c# - "application/vnd.ms-xpsdocument"mimetype 的 C# 常量是什么?

c# - TimeSpan ToString 格式

c# - 为什么使用 Decimal.Multiply 与运算符乘法?

c# - ListView 项目绑定(bind)

c# - 将 WPF (XAML) 控件转换为 XPS 文档

c# - 如何在 Windows 中使用 UniDrv 或 XPS 驱动程序 v3 设置虚拟打印机和显示器