The purpose of this document is to provide the ways to troubleshoot the issues related to PrintToPrinter() when used in .NET applications for printing Crystal Reports.
Overview
PrintToPrinter() is either used to the print the report to a printer or to a file. It has 3 overloads that can be used depending upon the requirement.
Overload list | Description |
---|---|
PrintToPrinter(int nCopeis, bool collated, int startPageN, int endPageN) |
|
PrintToPrinter(System.Drawing.Printing.PrinterSettings printerSettings, System.Drawing.Printing.PageSettings pageSettings, bool reformatReportPageSettings) |
|
PrintToPrinter(System.Drawing.Printing.PrinterSettings printerSettings, System.Drawing.Printing.PageSettings pageSettings, bool reformatReportPageSettings, PringLayoutSettings PrintLayout ) |
|
While printing the report from the application using PrintToPrinter(), some of the problems are often seen with scaling, orientation, customer paper sizes, fonts, spacing driver specific or driver access, tray access, not able to set the printer when a network printer is used, and when output goes to a default printer rather than desired printer etc... Some of the known errors are:
This document would focus on PrintToPrinter(System.Drawing.Printing.PrinterSettings printerSettings, System.Drawing.Printing.PageSettings pageSettings, bool reformatReportPageSettings, PringLayoutSettings PrintLayout ) and the the reason for using it is that; System.Drawing.Printing Namespace gives more granular control over PaperSize, PaperSource, Margins, PageSettings etc... than the PrintOptions settings used when using the first overload for PrintToPrinter() moreover CrystalDecisions.Shared.PrintLayoutSettings class helps specify custom layout options.
As per the scenarios given above, following resolutions work most of the times. However, it should be ensured that printer is installed on the machine where application is deployed and drivers are updated to the latest. User/identity/process should have access to the printer. To check if the user/ identity/process running the application has rights to access the printer, implement the code given in KB1418378 - How to determine what printers are available to a process in Visual Studio .NET. The code given in the above knowledge base article is most useful in web applications where the process executing the report is running under a different user context, though it can also prove useful when troubleshooting thick client applications.
Resolution 1
Follow the steps:
If selecting No Printer is not an option then go for the code given below.
Use the following code for printing the reports:
Sample Code |
---|
ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath("ReportName")); System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument(); CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings(); System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = "PinterName"; System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings); rpt.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true; rpt.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex; rpt.PrintToPrinter(printerSettings, pSettings, false, PrintLayout); |
Related Documents
Crystal Report printing inconsistancies in .NET
Server side printing with Crystal .NET SDK
How Printer Driver Options Affect a Report
Crystal Reports .NET SDK API Reference
Related Notes
1715391 - Crystal Reports PrintToPrinter API for .NET not responding on WIN 2008 Server
1549797 - Printing differences between Crystal designer and .NET SDK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |