WPF: Is there a way to use PrintDialog only to select the target printer without having to provide a DocumentPaginator class?

StackOverflow https://stackoverflow.com/questions/16016874

  •  04-04-2022
  •  | 
  •  

Question

I want to print a very simple layout with PrintDocument that fits on one page, so it doesn't require a DocumentPaginator. However I want to use PrinterDialog to select the printer. I saw examples with PrinterSettings being a property of PrinterDialog and it was simply assigned to the PrintDocument. But this doesn't seem to be possible anymore. I also looked for other solutions like custom paginator classes to use but came up empty. I might not have this deep insight into WPF, but why must it always be dongled that way...

Was it helpful?

Solution

Try this:

  • Import System.Printing
  • Create a PrintDialog

And then:

PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = new PrintQueue(new PrintServer(), "PrinterName");
printDialog.PrintDocument(document, "PrintDocument");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top