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);