'PrintTicket for every FixedPage lost when using XpsSerializationManager
Sample code:
public static void MakeXPS(FixedDocument fixedDoc, PrintTicket ticket, Stream os)
{
using (Package package = Package.Open(os, FileMode.Create))
{
var inMemPackageName = $"memorystream://foo.xps";
Uri packageUri = new Uri(inMemPackageName);
PackageStore.RemovePackage(packageUri);
PackageStore.AddPackage(packageUri, package);
using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Fast, inMemPackageName))
{
var paginator = ((IDocumentPaginatorSource)fixedDoc).DocumentPaginator;
/*paginator.ComputePageCount();
int pageCount = paginator.PageCount;
for (int i = 0; i < pageCount; ++i)
{
DocumentPage docPage = paginator.GetPage(i);
using (docPage)
{
// every FixedPage has its own PrintTicket
//((FixedPage)docPage.Visual)...
}
}*/
XpsPackagingPolicy policy = new XpsPackagingPolicy(xpsDoc);
using (var manager = new XpsSerializationManager(policy, false))
{
policy.PersistPrintTicket(ticket); // original printticket for document with default settings
manager.SaveAsXaml(paginator); // <-- does NOT save the printtickets attached to every FixedPage in the fixedDoc object
manager.Commit();
}
PackageStore.RemovePackage(packageUri);
}
}
}
In the code above you see that we create a new XPS document from a given FixedDocument.
The FixedDocument fixedDoc contains several FixedPages each page having its own PrintTicket.
The PrintTicket ticket is a PrintTicket on document level (e.g. kind of 'default print settings').
When we use the XpsSerializationManager to create the XPS file, the PrintTickets attached to every page (FixedPage) are gone.
Why does XpsSerializationManager not save the PrintTickets at page level? Do I need to configure anything special?
(+ additional small question: should PackageStore.RemovePackage(packageUri); be done before XpsDocument.Close() or after (outside the using-statement)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
