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

Printing Directly from Web Server

9 Answers 336 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Luz Milian
Top achievements
Rank 1
Luz Milian asked on 27 Aug 2009, 07:05 PM
Hi,

I am trying to Print directly without any printer window.

I am using the following code:
-------------------------------------------------------------------------------------------------------------------
                     'Instance the report with all the information already populated
                    Dim IdCardReportToPrint As New IdCardReport

                    'Set the Printer Setting
                    Dim CustomPrinterSettings As New System.Drawing.Printing.PrinterSettings
                    CustomPrinterSettings.PrinterName = "IDCardPrinter" '

                   'Print Directly
                    Dim ReportPrint As New Telerik.Reporting.Processing.ReportProcessor
                    ReportPrint.PrintReport(IdCardReportToPrint , CustomPrinterSettings)
-------------------------------------------------------------------------------------------------------------------

It worked fine in the developer machine, it prints directly without any windows. Ones we deployed in the web server we are getting the following error:

ERROR ***********************************

08/27/2009 14:00:06
Type : System.InvalidOperationException
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.
Source : System.Windows.Forms

END ERROR****************************************

I think what is happening is when we send to print it try to print in the server. Does this function print in the local machine or in the server?

We also use this article to print but it show the printers windows of the explorer and we dont want it. Any ideas?

Best Regards.


9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 Aug 2009, 12:07 PM
Hi Luz Milian,

Using server-side code for printing the report would end up printing the report on the server the application is being run on and this is expected behavior. For web apps/sites, you should use the client-side printing mechanism:

   <telerik:ReportViewer runat="server" id="ReportViewer1"></telerik:ReportViewer>                      
    <script type="text/javascript">
        <%=ReportViewer1.ClientID %>.PrintReport();
    </script>      

Printing with predefined/chosen printer is not possible on the client side as this would be a security vulnerability i.e. it is not even possible to get the list of available printers for the same reason.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Luz Milian
Top achievements
Rank 1
answered on 28 Aug 2009, 12:48 PM
Hi Steve, thanks for your answer.

The line of code you send works fine but it shows me the Print Dialog Window to select the printer. Can I use the same line without the Print Dialog?

Can I also send to print from the client side with this method?
                    'Print Directly
                    Dim ReportPrint As New Telerik.Reporting.Processing.ReportProcessor
                    >>>>> USE THIS METHOD FROM CLIENT SIDE>>>>
                  ReportPrint.PrintReport(IdCardReportToPrint , CustomPrinterSettings) (It possible?)


0
Steve
Telerik team
answered on 28 Aug 2009, 12:50 PM
Hi Luz Milian,

I've already explained in my previous reply, why both things are not possible. Please read carefully my reply as it holds the answers to your original questions.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Luz Milian
Top achievements
Rank 1
answered on 28 Aug 2009, 03:44 PM
Hi Steve,

We finally have everything working and we still have one problem. The Print Dialog Window that we use from your code, we need to know if there is a confirmation of printing, what we want to know is if the person click PRINT or Cancel in the Print Dialog Window or if we use the regular Icon Print from the Printviewer can we get a true or false of the printing?

Thanks.


0
Svetoslav
Telerik team
answered on 31 Aug 2009, 02:12 PM
Hello Luz Milian,

Please find our answer to a very question here.
 

All the best,
Svetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Scott
Top achievements
Rank 1
answered on 18 Dec 2009, 10:19 PM
How would you accomplish this if you're using the silverlight viewer?
0
Steve
Telerik team
answered on 19 Dec 2009, 03:30 PM
Hi Scott,

As you may probably know there is no printing support in Silverlight 3 (and previous versions). Still Telerik Reporting is capable of printing reports on the client-side using a technique similar to the Web Report Viewer. In order to print the current report programatically one should use the ReportViewerModel.PrintReportCommand; to obtain the ReportViewerModel use the viewer's data context:

var model = (ReportViewerModel)this.ReportViewer1.DataContext;
object ignored = null;
model.PrintReportCommand.Execute(ignored);
Regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Swetha
Top achievements
Rank 1
answered on 02 Jul 2013, 05:53 PM
Hi Steve,

I am also getting the same error when i print on server application though i dont get any errors in my local. I am using teh below code.

  rptBook.Reports.Add(objRptSingleVehicleReportExport);
                rptBook.Reports.Add(objrptPDFCoreAssumption);
                rptViewerExport.Report = rptBook;
                Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
                System.Drawing.Printing.PrinterSettings p = new System.Drawing.Printing.PrinterSettings();
               
                Telerik.Reporting.IReportDocument r = rptBook;
                reportProcessor.PrintReport(r, p);


I tried the to use script to print from client side but i get an popup in my local saying document cannot be printed.
I used the below script in aspx.cs page
 var printScript = "";

                printScript += "ReportViewer.OnReportLoadedOld = ReportViewer.OnReportLoaded;";

                printScript += "ReportViewer.prototype.OnReportLoaded = function()";

                printScript += "{";

                printScript += rptViewerExport.ClientID + ".PrintReport();";

                printScript += "ReportViewer.OnReportLoaded = ReportViewer.OnReportLoadedOld;";

                printScript += "}";

                if (ScriptManager.GetCurrent(base.Page).IsInAsyncPostBack)
                    ScriptManager.RegisterStartupScript(this, GetType(), "ReportPrint", printScript, true);
                else
                    this.Page.ClientScript.RegisterStartupScript(typeof(Page), "CallPrintDocument", printScript);



0
Stef
Telerik team
answered on 05 Jul 2013, 03:25 PM
Hi Swetha,

About your first code snippet, as explained in the Hide the print progress dialog when printing a report programmatically help article:
"This approach is only applicable for desktop applications (WPF, Windows Forms and etc.). If this code sample is used in server-client environment the print operation will be executed on the server side."

Since you have mentioned here that the client-side printing does not work only in Chrome, please check the used PDF plug-in and the following troubleshooting article Chrome: Adobe PDF plug-in

If you need further help, please elaborate on the situation in which the printing fails, used Telerik Reporting release and send us more details about your project and printed report definition.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Luz Milian
Top achievements
Rank 1
Answers by
Steve
Telerik team
Luz Milian
Top achievements
Rank 1
Svetoslav
Telerik team
Scott
Top achievements
Rank 1
Swetha
Top achievements
Rank 1
Stef
Telerik team
Share this question
or