The following methods can be used to print Crystal Reports under ASP. NET:
1. use IE printing to call window. print (). However, this method cannot be distinguished when there are reports on the page and other controls. It cannot only print the report content;
2. Write and print your own code
The Code is as follows:
Reference content is as follows: CrystalDecisions. CrystalReports. Engine. ReportDocument rd = new CrystalDecisions. CrystalReports. Engine. ReportDocument (); Rd. Load (Server. MapPath ("Crystalreport1.rpt ")); Rd. PrintOptions. PrinterName = "Printer name "; Rd. PrintToPrinter (1, true, 0, 0 ); |
"Printer name": for a network printer, add "\ MACHINE name" before the printer name. The local printer can also be displayed in the DropDownList control for the user to select:
Reference content is as follows: Foreach (string iprt in System. Drawing. Printing. PrinterSettings. InstalledPrinters) This. DropDownList1.Items. Add (iprt ); |
This method can print only the content in the report, but the printer name must be specified. if the local printer is okay, You can enumerate it and let the user select it. however, if it is a network printer, it seems a little troublesome. I still don't know how to list the network printer for the user to choose, or automatically select the default network printer.
3. Export to a PDF, EXCEL, or other format file for printing. The sample code is as follows:
Report Name myrpt = new report name ();
Reference content is as follows: Myrpt. ExportOptions. ExportDestinationType = CrystalDecisions. Shared. ExportDestinationType. DiskFile; Myrpt. ExportOptions. ExportFormatType = CrystalDecisions. Shared. ExportFormatType. PortableDocFormat; CrystalDecisions. Shared. DiskFileDestinationOptions opt = new CrystalDecisions. Shared. DiskFileDestinationOptions (); Opt. DiskFileName = @ "file name "; Myrpt. ExportOptions. DestinationOptions = opt; Myrpt. Export (); |