I created a report that will be used in a Forms application and web.
In the form app, I click in a button and send the report directly to the printer.
I want to do the same thing in a web app.
Is there a way without the ReportViewer? I mean, in the forms app I call the ReportProcessor.PrintReport(report, PrinterSettings). some way to do the same but in the web.
Thanks,
Ezequiel
17 Answers, 1 is accepted
You can review the following article (How to print report on client machine without showing the report) where the report is being hidden and its client API is used to print the report. Another approach for printing a document without using the ReportViewer control is to have 2 pages: MainForm.aspx from which the request will be triggered and PrintForm.aspx which will serve the print report. Here is the concrete implementation of both pages:
MainForm.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MainForm.aspx.cs" Inherits="MainForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
head
runat
=
"server"
>
<
title
></
title
>
<
script
type
=
"text/javascript"
>
function PrintReport() {
var printFrame = document.getElementById("PrintFrame");
printFrame.src = "PrintForm.aspx?tmp=" + new Date().getTime();
}
</
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
iframe
id
=
"PrintFrame"
src
=
"javascript:'';"
style
=
"visibility:hidden;"
width
=
"1px"
height
=
"1px"
></
iframe
>
<
asp:Button
ID
=
"Button1"
Text
=
"PrintReport"
runat
=
"server"
Height
=
"20px"
OnClientClick
=
"PrintReport(); return false;"
/>
<
br
/>
</
div
>
</
form
>
</
body
>
</
html
>
PrintForms.aspx.cs:
public
partial
class
PrintForm : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
Hashtable deviceInfo =
new
Hashtable();
deviceInfo[
"JavaScript"
] =
"this.print({bUI: false, bSilent: true, bShrinkToFit: true});"
;
ReportProcessor reportProcessor =
new
ReportProcessor();
RenderingResult result = reportProcessor.RenderReport(
"PDF"
,
new
BarcodesReport(), deviceInfo);
string
fileName = result.DocumentName +
".pdf"
;
Response.Clear();
Response.ContentType = result.MimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer =
true
;
Response.BinaryWrite(result.DocumentBytes);
Response.End();
}
}
The code is self-explanatory but if you have any questions about it, please let me know.
Have in mind that printing silently is not somewhat advisory so the PDF plug-in will show a message that the document is trying to print although not displaying the Print dialog.
Hope this helps.
Regards,
Steve
the Telerik team
Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

Or how could i print automatic in MVC Project?

I recently came upon this thread and I've implemented the solution suggested by Steve. When debugging locally, I receive a pop-up stating: "This document is trying to print. Do you want to allow this?", which is fine. However, when I deploy this to our server I am asked if I want to open, download or save the document, when I click open, Adobe Reader opens, and then the same message is displayed. Is there a reason why Adobe Reader opens when I access the app from the server?
Thanks!
Casey
The experienced printing behavior is caused due to the PDF JavaScript print arguments. Generally the used arguments will try to suppress the print dialog and this causes the browsers security alert. If you want to invoke the print dialog instead you can use the following arguments:
deviceInfo[
"JavaScript"
] =
"this.print({bUI: true, bSilent: false, bShrinkToFit: true});"
;
About the deployed application behavior check out the True Print help article that elaborates on the common troubles with the PDF plugins and If you need further assistance we will appreciate if you share more information on your configuration such as OS, browser and PDF plugin version. Greetings,
Peter
the Telerik team

Thanks for that code. It seems to do the trick in IE 9.
I think I figured out why it wasn't working properly before though. When debugging locally the 32-bit version of IE9 would open, and it would use the 32-bit Adobe Reader plugin. When I would access the website on the server, I was using the 64 bit version of IE 9, which, I'm guessing, has trouble using the 32-bit Adobe Reader plugin.
Does that sound like it should be causing the issue with Adobe opening, rather than just the print dialog opening?
Thanks!
Casey
Edit - Just found this link and the last reason for not being able to view a PDF on the web is: "You are using a 64-bit version of the Internet Explorer browser."
Can't View PDF on the web

I am successfully using this method to send a report to a local printer from the client, but I have a situation where I need to send multiple reports. My application uses a signature scanner to grab a clients signature and then needs to print a number of separate reports with that signature on them. I've tried a number of methods but none of them work, printing only the last report that was sent. is there a way to do this?
I am using HttpContext.Current.ApplicationInstance.CompleteRequest() instead of Response.End() since Response.End() terminates further processing of the page.
Here's what I've tried so far,
- Create a single ReportProcessor and doing a BinaryWrite of each RenderingResults to it, followed by one CompleteRequest
- Create a single ReportProcessor and doing a BinaryWrite followed by a CompleteRequest for each RenderingResult
- Create a separate ReportProcessor for each RenderingResult with a BinaryWrite and CompleteRequest for each of them
- Create a separate ReportProcessor for each RenderingResult with a BinaryWrite followed by a single CompleteRequest
And so on... Nothing works. Is there a way to do this? Perhaps concatenating all of the reports into a single report, how would I do that?
Another problem is that after the page is finished, whether I am attempting to print one or more reports, I get this error,
Microsoft JScript runtime error: 'type' is null or not an object
It is on this line of code in an unknown script file (identified only by a long Hex number)
var etype = this.type = e.type.toLowerCase();
This appears to be related to the printing of the report, since it doesn't appear if I comment out all the printing related code.
Any help on this?
Thank you,
John

Cheers!

John

I have a problem with the reportviewer in VB.Net. 2012.
I'm trying to determine if a user has printed a report from the ReportViewer control, so I can write the date/time and username to a database table as part of an audit trail.
When the user opens a report there is a print button, which calls up a standard print dialog box. However I can't find any way to determine whether the print button has been clicked or not. The reportviewer has a Print event, but this is no good as it's called before the print dialogue is displayed.
What I ideally need to do is to check the status of the print dialog form to see if the user clicked Print or Cancel. But there seems to be no clear way to do this...
Any ideas?
As of Q3 2014 we exposed viewers' API allowing you to detect the start and end of print/export operation. In a consecutive release there will be added more information in this events for the status of the operation and its result.
If it is an emergency to implement the feature, you will have to handle the export/print programmatically through the ReportProcessor - Exporting Report Programmatically. Depending on the used technology e.g., ASP.NET, Silverlight, you may want to substitute the print operation with export into PDF with injected Javascript forcing the PDF reader to start its Print dialog on opening the file - Print a report directly at client-side without displaying it in an ASP.NET ReportViewer.
I hope the above information is helpful.
Regards,
Stef
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Hello
My asp.net project is on web based. I have crystal reports in my project. But I have not inserted reportviewer. My application works like clicking on Print button the print dialog box will appear and the crystal report will be printed.
protected void btnPrint_Click(object sender, EventArgs e)
{
// ReportDocument rDoc = new ReportDocument();
//rDoc.Load("C:/Users/SUDESHNA/Documents/Visual Studio 2010/Projects/Inventory/SoldCrystalReport.rpt");
//rDoc.SetParameterValue("@Category", ddlCategory.SelectedValue);
//rDoc.SetDatabaseLogon("sa", "gariahat");
//this.crystalReportViewer.ReportSource = rDoc;
//this.crystalReportViewer.DataBind();
//this.crystalReportViewer.Focus();
//rDoc.Refresh();
//rDoc.PrintToPrinter(1, true, 0, 0);
ReportDocument rDoc = new ReportDocument();
PrintDialog dialog1 = new PrintDialog();
rDoc.Load(Server.MapPath("SoldCrystalReport.rpt"));
rDoc.SetParameterValue("@Category", ddlCategory.SelectedValue);
rDoc.SetDatabaseLogon("sa", "gariahat");
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;
rDoc.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
rDoc.PrintToPrinter(copies, collate, fromPage, toPage);
}
rDoc.Dispose();
dialog1.Dispose();
This is the code I have written and I am getting error the same as showing a modal dialog box.......
Can you please tell me what changes I need to do it in the code. please its an urgent, I will be greatful if someone tell me

The example in the post before yours will be executed on the server, and you must have set correct PrinterSettings to avoid modal dialogs on the server.
The example provided by my colleague Peter illustrates how to print at the client - export the report in PDF with additional settings to force the Print operation in the PDF reader.
Regards,
Stef
Telerik

I am getting error at Line 5 at HashTable
line 6 at DeviceInfo and line 9, 10,11 13 and 20 can you help
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Hashtable deviceInfo = new Hashtable();
deviceInfo["JavaScript"] = "this.print({bUI: false, bSilent: true, bShrinkToFit: true});";
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", new BarcodesReport(), deviceInfo);
string fileName = result.DocumentName + ".pdf";
Response.Clear();
Response.ContentType = result.MimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer = true;
Response.BinaryWrite(result.DocumentBytes);
Response.End();
Please test to modify the code based on Print a report directly at client-side without displaying it in an ASP.NET ReportViewer.
If you are running VS2013 or greater, run the application with disabled BrowserLink.
If you need further help, please elaborate on the received error.
Regards,
Stef
Telerik

PDF files are opened in browser thanks to the PDF plugin available in the browser. Without a plugin that can handle the given document format, the browser will start a download without loading the document in preview.
Regards,
Stef
Telerik by Progress