How to show print dialog in Crystal Report?

I want to print my Crystal report directly to the printer. I am currently exporting to PDF . But my client wants this to switch directly to the printer. How can I show Print Dialog when I click the Print button to print the report directly to the printer.

I would like to mention: I am using C # and asp.net for my project.

Thanks.

+4
source share
3 answers

Try using the following code

  private void Button1_Click(object sender, EventArgs e) { CrystalReport1 report1 = new CrystalReport1(); PrintDialog dialog1 = new PrintDialog(); report1.SetDatabaseLogon("username", "password"); dialog1.AllowSomePages = true; dialog1.AllowPrintToFile = false; if (dialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int copies = dialog1.PrinterSettings.Copies; int fromPage = dialog1.PrinterSettings.FromPage; int toPage = dialog1.PrinterSettings.ToPage; bool collate = dialog1.PrinterSettings.Collate; report1.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName; report1.PrintToPrinter(copies, collate, fromPage, toPage); } report1.Dispose(); dialog1.Dispose(); } 

you will need to change the "username" and "password" with the credentials of your database.

EDIT

This code can only be used for server-side printing.

+2
source

In no way; Cristal Report Viewer is designed to display and view the report.
It never shows all pages of a report.
It has no buttons or methods for direct printing. A.

Instead, you can directly export the report in PDF format so that report viewers are never seen by users, and printing becomes a one-click operation.

0
source

PrintButton_click event and add the following code as you ..

  //show Print Dialog PrintDialog printDialog = new PrintDialog(); DialogResult dr = printDialog.ShowDialog(); if (dr == DialogResult.OK) { ReportDocument crReportDocument = (ReportDocument)CrystalReportViewer1.ReportSource; System.Drawing.Printing.PrintDocument printDocument1 = new System.Drawing.Printing.PrintDocument(); //Get the Copy times int nCopy = printDocument1.PrinterSettings.Copies; //Get the number of Start Page int sPage = printDocument1.PrinterSettings.FromPage; //Get the number of End Page int ePage = printDocument1.PrinterSettings.ToPage; crReportDocument.PrintOptions.PrinterName =printDocument1.PrinterSettings.PrinterName; //Start the printing process. Provide details of the print job crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage); 

// Form_Printerd = true; }

0
source

Source: https://habr.com/ru/post/1489074/


All Articles