This is a migrated thread and some comments may be shown as answers.

Telerik Reporting Print Dialog Box

17 Answers 835 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 28 Jan 2011, 11:39 PM
Hi,

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

Sort by
0
Steve
Telerik team
answered on 02 Feb 2011, 03:14 PM
Hello Muhammad,

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:
Copy Code
<%@ 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:
Copy Code
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
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Muhammad
Top achievements
Rank 1
answered on 22 Feb 2011, 05:32 PM
Thank You so much ... this is what I really want ...
0
Muhammad
Top achievements
Rank 1
answered on 10 Mar 2011, 08:58 PM
Last time you gave me a very positive reply and again I am expecting the same from you if you solve my problem regarding my question below.

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;
        }
0
john doe
Top achievements
Rank 1
answered on 16 Jun 2011, 08:42 AM
Is there any solution found to this error message "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"

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
0
Vijetha
Top achievements
Rank 1
answered on 24 Oct 2011, 11:55 AM
Hi ,

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

0
Swetha
Top achievements
Rank 1
answered on 02 Jul 2013, 05:12 PM
Hi Steve,

i am gettig the below error
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. 
in my website when i print a report. It works fine in my development environment. Please suggest.
0
Stef
Telerik team
answered on 05 Jul 2013, 04:20 PM
Hello everyone,

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.

0
Support ATT
Top achievements
Rank 1
answered on 15 Oct 2013, 04:04 PM
 
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;
    }




0
Stef
Telerik team
answered on 15 Oct 2013, 06:45 PM
Hello,

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.

0
Support ATT
Top achievements
Rank 1
answered on 16 Oct 2013, 06:18 AM
Hi Stef,

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.
0
Stef
Telerik team
answered on 16 Oct 2013, 08:32 AM
Hello,

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.

0
Support ATT
Top achievements
Rank 1
answered on 27 Dec 2013, 10:09 AM

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



0
Stef
Telerik team
answered on 31 Dec 2013, 02:13 PM
Hi 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.

0
Support ATT
Top achievements
Rank 1
answered on 06 Jan 2014, 12:18 PM

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



0
Stef
Telerik team
answered on 08 Jan 2014, 05:53 PM
Hi David,

We have set the test project as follows:
  1. Implement a WCF Reporting service as illustrated in the How to: Self Host the Service
  2. Create a windows service that will open the Reporting service's ServiceHost on starting;
  3. Install the windows service and run it with your administrative credentials;
  4. 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.

0
Matthias
Top achievements
Rank 1
answered on 12 May 2015, 08:55 AM
Do you have an example? to use it as the WCF service seems not so clear to me...
0
Stef
Telerik team
answered on 12 May 2015, 03:09 PM
Hello Matthias,

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.

 
Tags
General Discussions
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Steve
Telerik team
Muhammad
Top achievements
Rank 1
john doe
Top achievements
Rank 1
Vijetha
Top achievements
Rank 1
Swetha
Top achievements
Rank 1
Stef
Telerik team
Support ATT
Top achievements
Rank 1
Matthias
Top achievements
Rank 1
Share this question
or