I would like to purchase telerik controls for my company but I will buy this product if you can provide me solution of below these problems because we are happy to buy this product.
Problem 1: I am using report Viewer for printing but every time when I click a button it shows a print dialog box which is very annoying sometimes. Is there anyway that I can set a default printer for that print button one time only.
Problem 2: I want to tell you that I have tried this method for directly send the job to the printer but it works fine in my development machine and the job goes directly to the printer but when I deployed the same code in the server the page never comes back.
Dim printerSettings As New System.Drawing.Printing.PrinterSettings
Dim standardPrintController As New System.Drawing.Printing.StandardPrintController
Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor
reportProcessor.PrintController = standardPrintController
reportProcessor.PrintReport(o, PrinterSettings)
17 Answers, 1 is accepted
Printing from the ReportViewer will always show the Print dialog and this behavior is not configurable. That is why we would suggest you another approach for printing a document without using the ReportViewer control.
To implement the suggested approach you should 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.
Best wishes,
Steve
the Telerik team
I am using Telerik Reporting for just printing in my windows service but what happen is that its showing a dialog box for printing and I am getting an exception. I have already defined a default printer name by my function. Any help would be greatly appreciated.
Exception :
Service cannot be started. System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = GetDefaultPrinter();
Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
System.Drawing.Printing.StandardPrintController standardPrintController = new System.Drawing.Printing.StandardPrintController();
Telerik.Reporting.Report rpt = new Telerik.Reporting.Report();
reportProcessor.PrintController = standardPrintController;
reportProcessor.PrintReport(rpt, printerSettings);
public string GetDefaultPrinter()
{
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
printerSettings.PrinterName = printer;
if (printerSettings.IsDefaultPrinter)
{
return printerSettings.PrinterName;
//return printer;
}
}
return string.Empty;
}
I use telerik reporting and i am trying to print from console application (console application calls web service application which does the printing and exporting).
Printing and exporting PDF documents (through) Telerik works OK on my development machine but on production machine it throws exception at the line "reportProcessor.PrintReport(rpt, printerSettings);"
Printer on the production machine is set as default printer.
Is there any specific printer settings to be concerned of or maybe application executing Telerik printing must be "run as" on some higher administrative account or is this impossible to achieve by design? (it is odd though that on the development machine printing works ok)
Thank you very much.
Damir
Even i got the same error message when i am using ReportProcesor in my WCF service
ErrorMsg:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
Below is my code
Telerik.Reporting.Processing.ReportProcessor reportproc = new Telerik.Reporting.Processing.ReportProcessor();
System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();
reportproc.Error += new Telerik.Reporting.ErrorEventHandler(reportproc_Error);
report1 obj =new report1();
reportproc.PrintReport(obj , settings);
This exactly works fine when i run the application on specific port(Use visual studio development server)
Does not not work for IIS webserver.
Please provide me the solution ASAp
Thanks,
vijetha
i am gettig the below error
Using the ReportProcessor to print in in server-client environment will execute the print operation on the server side. Please use the suggested approach in the How to print report on client machine without showing the report help article.
About the error you receive, you are trying to show a dialog box on the server. For more details check the discussion in the following msdn forum thread: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation.
I hope this helps.
Regards,
Stef
Telerik
Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.
Hello Stef
=> Using the ReportProcessor to print in in server-client environment will execute the print operation on the server side.
Yes, that is what i want, but without the Error caused PrintReport() Method.
I have a Webservice, who didn't work, with the same Error!
private void printToDefaultPrinter(string aactionNumber) { int aactionNr = int.Parse(aactionNumber); aaction.Load_AactionNumber(aactionNr); ExceptionLog.Instance.addMessage2Log("AactionNumber: " + aactionNumber); ReportSettings reportSetting = new ReportSettings(aaction.CompanyId); report = getReportAlarm(aactionNr, reportSetting.reportPrint.PrintLanguage, aaction.CompanyId); PrinterSettings printerSettings = new PrinterSettings(); printerSettings.PrinterName = GetDefaultPrinter(); ReportProcessor reportProcessor = new ReportProcessor(); reportProcessor.PrintController = new StandardPrintController(); InstanceReportSource instanceReportSource = new InstanceReportSource(); instanceReportSource.ReportDocument = report; ExceptionLog.Instance.addMessage2Log("Before PrintReport: " + aactionNumber); reportProcessor.PrintReport(instanceReportSource, printerSettings); ExceptionLog.Instance.addMessage2Log("After PrintReport: " + aactionNumber); } private string GetDefaultPrinter() { System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { printerSettings.PrinterName = printer; if (printerSettings.IsDefaultPrinter) { return printerSettings.PrinterName; //return printer; } } return string.Empty; }
As previously explained showing modal dialogs on the server is not supported. When you host your application in IIS server it runs under specific user profile not having interaction with the desktop and thus showing popups as those from the print job results in the following exception:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
You can create a separate desktop application to print programmatically the desired report, otherwise please test the suggested client-side print options.
Regards,
Stef
Telerik
Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.
Possibly you didn't understand me. I need to print the report Document on serverside. Not on client side. Can you provide me a solution? I need to access the default Printer on the Server.
Using ASP.NET and hosting the application in IIS would not allow you to perform the print operation on the server as required as the user under which is running the application does not have the required privileges to access the printer, causing the print dialog to be initialized.
It is preferable to create a separate desktop application using the same report library and print the report from it.
Regards,
Stef
Telerik
Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.
Hi Stef,
You talking about to print it form a desktop Applikation. And yes, it work's well.
But it's is also possible to print it as background Service as Windows Service. Is there any Way with the report print library of Telerik. With an older version it had worked, but with the newest one, it's didn't work anymore like before.
Thanks for your answer.
David
You can print programmatically report definition using the ReportProcessor.PrintReport method. Please verify you have granted access to the printer and all required printer settings are set in order not to invoke the Print Dialog.
If you need further help, please open a support ticket and send us the previously working project and details about the old and new used Telerik Reporting versions, including information about the applied access rules to allow the service to print before the upgrade.
Regards,
Stef
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.
Hi Stef
Well, I have granted access to the Printer. Could you give me an Example as a Windows Service with all required settings which set in order to not invoke the Print Dialog.
Thank you for your answer
David
We have set the test project as follows:
- Implement a WCF Reporting service as illustrated in the How to: Self Host the Service
- Create a windows service that will open the Reporting service's ServiceHost on starting;
- Install the windows service and run it with your administrative credentials;
- To print without showing the Print dialog, use the approach described in the Hide the print progress dialog when printing a report programmatically help article - use a timer or directly print a report definition on start.
Let us know if we miss any of your settings to replicate the issue.
Regards,
Stef
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.
The attached demo project contains a standard Windows Service project, where on start we are printing a report as many times as specified on starting the service. The code uses standard print controller to get the default printer settings of the machine and print without additional confirmations - ReportProcessor.PrintReport Method.
The project has an installer which operates with with the current user's account - ServiceProcessInstaller.Account Property(msdn). Thus the user must be an administrator of the machine to avoid any security popups on printing. The service is made to be started manually.
Details how to install and start the service are available in How to: Install and Uninstall Services(msdn) and How to: Start Services(msdn). Note that most probably you will need administrator account to install and run the service. With the given demo you will be prompt to specify the user on installing the service.
The accompanying video illustrates how to run it.
Regards,
Stef
Telerik
See What's Next in App Development. Register for TelerikNEXT.