I have an issue with the printing of XPS documents. The first print works correctly but then the print dialog and the prints appears corrupted as you can see in that image.
I tried to use other overloads of the Write function such as the one using a DocumentPaginator as a parameter or the PrintDocument function of the print dialog but it didn't work either.
I noticed that the results depend on the choice of printer. Using the Microsoft XPS Document Writer works correctly but use a real printer or a PDF printer didn't.
Here's the simplest code that reproduces the issue :
public void Execute(object parameter)
{
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
PrintDocument(
"xps_document_filename.xps",
printDialog);
}
}
private static void PrintDocument(string documentPath, PrintDialog printDialog)
{
using (var xpsDocumentSource = new XpsDocument(documentPath, FileAccess.Read))
{
XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
xpsDocumentWriter.Write(xpsDocumentSource.GetFixedDocumentSequence());
}
}