Crystal Report | Printing | Default Printer

30,203

Solution 1

Take a look at the ReportDocument.PrintToPrinter SAP Docs or MSDN Docs for how to specify the PrinterName and then Print using the ReportDocument object.

If you can try and get away from how the FoxPro app UI for printer selection. Instead use the standard print dialog box to select the printer.

You should note that if you don't set the PrinterName before sending the report to the printer it will use the default on the crystal file. Not to be confused with the user's OS default printer.

Here's an example of showing the PrintDialog settings some parameters using the SetParameterValue method and then sending the report document to a printer

// Note: untested
var dialog = new PrintDialog();

Nullable<bool> print = dialog.ShowDialog();
if (print.HasValue && print.Value)
{
    var rd = new ReportDocument();

    rd.Load("ReportFile.rpt");
    rd.SetParameter("Parameter1", "abc");
    rd.SetParameter("Parameter2", "foo");

    rd.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName;
    rd.PrintToPrinter(1, false, 0, 0);
}

Solution 2

The code above no longer works as advertised which has been admitted by SAP You need to set the report document to an ISCDReportClientDocument and then print it. This is a more robust way of making sure the print job doesn't go to the default printer. The last two lines can be replaced with this code.

    CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions printReportOptions = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
    CrystalDecisions.ReportAppServer.Controllers.PrintOutputController printOutputController = new CrystalDecisions.ReportAppServer.Controllers.PrintOutputController();
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
    rptClientDoc = cryRtp.ReportClientDocument;
    printReportOptions.PrinterName = pDialog.PrinterSettings.PrinterName;
    rptClientDoc.PrintOutputController.PrintReport(printReportOptions);

Here is another good link
http://mattruma.azurewebsites.net/?p=258

Share:
30,203
Akshay J
Author by

Akshay J

Updated on July 09, 2022

Comments

  • Akshay J
    Akshay J almost 2 years

    I am making one application where user will print invoices which I am displaying using Crystal Report.

    The user showed me his current application made using ForPro. In that application, under Printer Options form, one can see all the printers currently installed and the user could select default printer. When the invoice is made, the user presses the print button, then there is one dialog asking for no. of copies. When it's entered, the invoice gets printed directly, without any Print Dialog Box. If the user wants to change the printer again he/she will change it in the Printer Option form.

    I want to know if similar thing is possible in Crystal Report and need guidance on how to approach for it.

  • Akshay J
    Akshay J almost 13 years
    @Frix, My report also uses some parameters, the example there in MSDN does not allow to specify parameters.Please help !
  • aboy021
    aboy021 over 11 years
    Was actually useful, though the answer really isn't that clear.