I'm trying to load a XPS file from disk and print it as part of a FixedDocument
or FixedDocumentSequence
of in memory documents I've created. They need to be printed as one sequence because they're duplexed.
Here's my best attempt so far:
// create my memory FixedDocument (a packing slip)
DocumentReference mainDocRef = GetMainDoc(); // created in memory
// load XPS document from file (to print on the back)
XpsDocument xpsDoc = new XpsDocument("flyer.xps", FileAccess.Read);
var docSequenceFromFile = xpsDoc.GetFixedDocumentSequence();
var xpsDocRef = docSequenceFromFile.References.First();
// try to combine together
FixedDocumentSequence documentSequence = new FixedDocumentSequence();
documentSequence.References.Add(mainDocRef);
documentSequence.References.Add(xpsDocRef); // THROWS EXCEPTION
// print
XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(printQueue);
xps.Write(documentSequence, ticket);
I always end up with the exception :
InvalidOperationException : Additional information: Specified element is already the logical child of another element. Disconnect it first.
I've tried several ways to do this, but keep ending up with errors like this
How can I load an XpsDocument
and print it as a second page in a FixedDocumentSequence
I've created in memory?