0

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());
    }
}
  • I seriously doubt this has anything to do with the xps document and everything to do with your OS. Have you reproduced on a different machine? If so, open a connect with microsoft, I'm sure they'd love to see this. –  Feb 10 '16 at 14:53
  • You're right when I try this code on my Win 10 machine using the PDF printer provided by default, it works but I can't change the machines on which my application will be deployed. Basically, I'm screwed... – Anonyme Code Feb 11 '16 at 08:58
  • Those machines are screwed. If whoever is in charge of them refuses to reinstall/fix them, then *they* are the ones that are screwed. There is **absolutely nothing** you can do in code to fix this. –  Feb 11 '16 at 14:12

0 Answers0