C# WPF Paginator printer ignoring user's printer selection

Posted by Anders on Stack Overflow See other posts from Stack Overflow or by Anders
Published on 2010-05-30T17:41:34Z Indexed on 2010/05/30 17:42 UTC
Read the original article Hit count: 318

Filed under:
|
|

I am using the following code in my project. The print dialog shows, but it always prints on the default printer regardless of the user's selection. I have read similar topics but none of them seem to use the SerializerWriterCollator. What is the problem?

            PrintQueue printQueue = LocalPrintServer.GetDefaultPrintQueue();
            XpsDocumentWriter xpsWriter = PrintQueue.CreateXpsDocumentWriter(printQueue);
            SerializerWriterCollator batchPrinter = xpsWriter.CreateVisualsCollator();
var printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                PrintTicket ticket = printDialog.PrintTicket;
                ticket.PageOrientation = PageOrientation.Landscape;
                var paginator1 = new PagePrinter(winchFlightsCount,
                  new Size(printDialog.PrintableAreaWidth,
                    printDialog.PrintableAreaHeight), winchFlights);
                var paginator2 = new PagePrinter(tugFlightCount,
                  new Size(printDialog.PrintableAreaWidth,
                    printDialog.PrintableAreaHeight), tugFlights);
                var paginator3 = new PagePrinter(selfFlightCount,
                  new Size(printDialog.PrintableAreaWidth,
                    printDialog.PrintableAreaHeight), selfFlights);

                batchPrinter.BeginBatchWrite();

                for (int i = 0; i < paginator1.PageCount; i++)
                {
                    batchPrinter.Write(paginator1.GetPage(i).Visual, ticket);
                }
                for (int i = 0; i < paginator2.PageCount; i++)
                {
                    batchPrinter.Write(paginator2.GetPage(i).Visual, ticket);
                }
                for (int i = 0; i < paginator3.PageCount; i++)
                {
                    batchPrinter.Write(paginator3.GetPage(i).Visual, ticket);
                }

                batchPrinter.EndBatchWrite();
            }
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf