Print Crystal Report Directly in ASP.NET C#
1. CLIENT-SIDE PRINTING
This is the most ideal method in printing in a Web-based application as most users will be certainly accessing the server remotely.
Put this javascript code inside the head tag of your .aspx page where the crystal report viewer resides.
<script type="text/javascript">
function Print() {
var dvReport = document.getElementById("dvReport");
var frame1 = dvReport.getElementsByTagName("iframe")[0];
if (navigator.appName.indexOf("Internet Explorer") != -1) {
frame1.name = frame1.id;
window.frames[frame1.id].focus();
window.frames[frame1.id].print();
}
else {
var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.print();
}
}
</script>
With the same page, in the body tag put this
<body>
<form id="form1" runat="server">
<asp:Button ID="btnPrint" runat="server" Text="Print Directly" OnClientClick="Print()"></asp:Button>
<div id="dvReport">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" ToolPanelView="None" EnableDatabaseLogonPrompt="false" />
</div>
</form>
</body>
--
take note of the button in there. it should be outside the div that enclosed the crystal report viewer. This will surely work. see Full discussion on this method: http://www.aspsnippets.com/Articles/Print-Crystal-Report-on-Client-Side-on-Button-Click-using-JavaScript-in-ASPNet.aspx
2. SERVER SIDE PRINTING
The most suggested answers here is the printToPrinter() Function. This method is done on server-side, hence, it is limited when you are accessing the server of your Web-based application / website remotely, unless the client can map or have the access with the server printer.
Please read this for further info: http://aspalliance.com/509_Automatically_Printing_Crystal_Reports_in_ASPNET.3
Direct printing Crystal Report to Printer, instead of asking for print dialog(report viewer)
Have you tried the printtoprinter() method at run time? You can hide the default print button, add a custom print button that will make a call this method.
vb6 print Crystal report without preview and click print button
Try something like:
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report
Set crxApp = New CRAXDRT.Application
Set crxRpt = crxApp.OpenReport("C:\MyReport.rpt")
crxRpt.PrintOut False, NoCopies
If you need to print the report on other printer than default, try to use SelectPrinter.
Look at this page.
VB.NET 2013 Crystal Report print to printer directly without displaying
I found an alternate solution to this question. I used Commandline Switches for Adobe Acrobat from this site: https://www.robvanderwoude.com/commandlineswitches.php#Acrobat
Using this switch, I can send a PDF to a any physical printer. The PDF creation however is done using BullPDF printer (http://www.bullzip.com/products/pdf/info.php) which is a Free PDF printer application.
So the full logic is as follows:
Have a custom report designed per customer specifications in Crystal Reports 2013
Print the report from Crystal Reports to a PDF Printer using the following code:
Private Sub RunReport()
Dim CryRpt As New ReportDocument
Dim crTblLogInfos As New TableLogOnInfos
Dim crTblLogInInfo As New TableLogOnInfo
Dim crConInfo As New ConnectionInfo
Dim crTables As Tables
Dim crTable As Table
With crConInfo
.ServerName = ServerName
.DatabaseName = DBName
.UserID = UID
.Password = Pwd
End With
CryRpt.Load(FPath & "rptLink.rpt")
crTables = CryRpt.Database.Tables
For Each crTable In crTables
crTblLogInInfo = crTable.LogOnInfo
crTblLogInInfo.ConnectionInfo = crConInfo
crTable.ApplyLogOnInfo(crTblLogInInfo)
Next
CryRpt.PrintOptions.PrinterName = "Bullzip PDF Printer"
CryRpt.PrintToPrinter(1, False, 0, 0)
OrdersLinking.DocPrinted = True
Me.Close()
End Sub
- The above step would save the report as a PDF to a pre-defined folder as mentioned in Bull PDF Printer. Now send the PDF Files to the physical printer using the following commands as mentioned on https://www.robvanderwoude.com/commandlineswitches.php#Acrobat
Print a PDF file silently:
AcroRd32.exe /N /T PdfFile PrinterName
Mission Accomplished.
Related Topics
Using Linq to Groupby and Sum Datatable
How to Format a String as a Telephone Number in C#
How to Get Only Date from a Datetime Value in Razor Page
How to Get the Display Name Attribute of an Enum Member Via MVC Razor Code
Convert Date Format of String to Datetime Mm/Dd/Yyyy When System Date Formate Is Dd/Mm/Yyyy
How to Check If Data Exists Before Writing to Table
How to Prevent the Print Progress Dialog Appearing When Performing a Print Preview
How to Get Column Names of Table At Runtime in C#
Using Formflow Dialog in Bot Framework
How to Get the Xml Soap Request of an Wcf Web Service Request
First Call to Web API Is Very Slow C#
Securely Store a Password in the Application in C#
Deserialize Json String in to Multiple C# Objects
Convert Time With Milliseconds to Datetime in C#
Return Json, But It Includes Backward Slashes "\", Which I Don't Want
How to Insert 10 Million Records in the Shortest Time Possible
Truncate Two Decimal Places Without Rounding
How to Encrypt a Password Within Appsettings.Json for ASP.NET Core 2