2

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.

Gabriel GM
  • 6,391
  • 2
  • 31
  • 34
  • PageSetupDialog doesn't provide "the printer option", its Document property does. Select the printer first, the page setup next. – Hans Passant Nov 19 '12 at 22:26
  • The problem is I can select the papersource in the `PrintDialog` window, but I can't get it in the code to send it back to my document. – Gabriel GM Nov 20 '12 at 13:14
  • You need to assign the PrintDialog.Document property. – Hans Passant Nov 20 '12 at 13:15
  • My bad, I forgot to mention I'm trying to do this for Crystal report (my ReportDocument is `CrystalDecisions.CrystalReports.Engine.ReportDocument`. Editing my question. – Gabriel GM Nov 20 '12 at 13:48
  • Found my answer, thanks for the comment Hans, it guided me! I'll post it when it'll fully tested. – Gabriel GM Nov 20 '12 at 14:00

1 Answers1

0

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);
Gabriel GM
  • 6,391
  • 2
  • 31
  • 34