I'm trying to send multiple documents directly to the printer after selecting print options from the PrintDialog
class.
I need to retrieve the selected papersource. Unfortunatly, I can only find all papersources from the printer, not the selected one.
Here is a sample of my code (shorten version):
CrystalDecisions.CrystalReports.Engine.ReportDocument document;
//...
PrintDialog pDialog = new PrintDialog();
pDialog.ShowDialog();
document.PrintOptions.PrinterName = pDialog.PrinterSettings.PrinterName; //OK
//Here I need to set the papersource
//document.PrintOptions.PaperSource = ???
document.printToPrinter(pDialog.PrinterSettings.Copies, false, 0, 0)
Am I using the good object to do this?
Note: the PageSetupDialog
doesn't provide me the printer option since i'm using windows 7.
I found the answer to my question with Hans Passant comment. Thanks to him.
In order to get the PaperSource
from the PrintDialog
, I had to set a fake PrintDocument
to it.
The PrintDialog
doesn't keep the papersource directly. Instead, it sets the PrintDialog.Document.DefaultPageSettings.PaperSource
.
Here is what it looks like:
CrystalDecisions.CrystalReports.Engine.ReportDocument document;
PrintDialog pDialog = new PrintDialog();
pDialog.Document = new System.Drawing.Printing.PrintDocument();
pDialog.ShowDialog();
document.PrintOptions.PrinterName = pDialog.PrinterSettings.PrinterName;
document.PrintOptions.CustomPaperSource = pDialog.Document.DefaultPageSettings.PaperSource;
document.printToPrinter(pDialog.PrinterSettings.Copies, false, 0, 0);