In my WPF app, I have several FixedDocument objects, which I want to display together in a DocumentViewer, as if they were a single document.
It's easy to display a single FixedDocument in a document viewer:
myDocumentViewer.Document = myFixedDocument;
My first idea was to create a FixedDocumentSequence of all my FixedDocuments (which can also be set as the DocumentViewer.Document value as it implements IDocumentPaginatorSource). But when building a FixedDocumentSequence, one can only add to a collection of DocumentReference objects. There is no straightforward way to add a FixedDocument directly, and I can't figure out how to create and add a DocumentReference which is somehow linked to one of my FixedDocuments.
My second idea was to create a master FixedDocument, and then loop through all the FixedDocuments, and move their pages into the master FixedDocument. But I run into all sort of issues when trying to do this (to do with pages already belonging to another document (with no ability to remove them from that document! etc. etc.)
My third idea was to create and build a temporary XpsDocument, and retrieve the FixedDocumentSequence that it automatically seems to create. I've looked at this a bit, but it's getting to be what feels needlessly complex, so I thought I'd post here first to see if there are any other ideas, or help with my first two attempts!
Figured it out.
You can in fact, dynamically create DocumentReference objects linked to FixedDocuments:
var documentReference = new DocumentReference();
documentReference.SetDocument(document);
fixedDocumentSequence.References.Add(documentReference);
I'm not quite sure how I missed the SetDocument
method before. I think I must have been looking for a DocumentReference.Document
property with getter/setter. It is a little inconsistent in the .NET framework to instead have GetDocument and SetDocument methods, in my opinion.