ASP. NET Crystal Report for Printing

Source: Internet
Author: User

 

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 ();
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.