Printing Directly from Web Server

10 posts, 0 answers
  1. Luz Milian
    Luz Milian avatar
    4 posts
    Member since:
    Jul 2009

    Posted 27 Aug 2009 Link to this post

    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.


  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 28 Aug 2009 Link to this post

    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.
  3. DevCraft banner
  4. Luz Milian
    Luz Milian avatar
    4 posts
    Member since:
    Jul 2009

    Posted 28 Aug 2009 Link to this post

    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?)


  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 28 Aug 2009 Link to this post

    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.
  6. Luz Milian
    Luz Milian avatar
    4 posts
    Member since:
    Jul 2009

    Posted 28 Aug 2009 Link to this post

    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.


  7. Svetoslav
    Admin
    Svetoslav avatar
    649 posts

    Posted 31 Aug 2009 Link to this post

    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.
  8. Scott
    Scott avatar
    43 posts
    Member since:
    Nov 2007

    Posted 18 Dec 2009 Link to this post

    How would you accomplish this if you're using the silverlight viewer?
  9. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 19 Dec 2009 Link to this post

    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.
  10. Swetha
    Swetha avatar
    14 posts
    Member since:
    Apr 2013

    Posted 02 Jul 2013 Link to this post

    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);



  11. Stef
    Admin
    Stef avatar
    3050 posts

    Posted 05 Jul 2013 Link to this post

    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.

Back to Top
DevCraft banner