获取FixedDocuments出一个固定文档序列的 [英] Get FixedDocuments out of a FixedDocumentSequence
问题描述
很简单:
我有我拉过盘的XPSDocument。我想获得FixedDocuments出这个XpsDocument的,但我已经打了一下栽了跟头,因为我只能得到一个固定文档序列,我可以不知道如何从这个序列拉XpsDocuments。
I have an XPSDocument that I am pulling off of disk. I would like to get the FixedDocuments out of this XpsDocument, but I've hit a bit of a cropper since I can only get a FixedDocumentSequence, and I can't work out how to pull the XpsDocuments from this sequence.
到目前为止,我已经试过类似:
So far I've tried something like:
FixedDocument doc = (FixedDocument)myFixedDocSequence.References.First();
这是投不工作,但它说明了什么我想要实现的。
That cast doesn't work, but it illustrates what I'm trying to achieve.
推荐答案
myFixedDocSequence.References.First();
应该返回一个 DocumentReference的
。从这个代替铸造你试图使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.documents.documentreference.getdocument%28v=VS.100%29.aspx"><$c$c>DocumentReference.GetDocument$c$c>法,它返回一个固定文档
?在code是这样的:
myFixedDocSequence.References.First();
should return a DocumentReference
. From that instead of casting have you tried using the DocumentReference.GetDocument
method, which returns a FixedDocument
? The code would look like this:
DocumentReference docReference = myFixedDocSequence.References.First();
FixedDocument doc = docReference.GetDocument(false);
阅读链接到上面的 GetDocument
参数选项的详细信息的文档。此外,除非你确定 References.First()
将不能为空,可以考虑使用 FirstOrDefault()
和检查对于空之前使用返回的对象。
Read the documentation linked to above for more information on the GetDocument
parameter options. Also unless you're sure References.First()
won't be null, consider using FirstOrDefault()
and checking for null before using the returned object.
这篇关于获取FixedDocuments出一个固定文档序列的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!