How do I get print preview when user clicked on print button

2 posts, 0 answers
  1. Oguzhan
    Oguzhan avatar
    2 posts
    Member since:
    Dec 2013

    Posted 10 Oct 2014 Link to this post

    Below is the sample code (I’M generating reports programmatically
    from JSON data)



    public static void Export(Telerik.Reporting.ReportBook reportToExport, string type, string cType)

            {

     

                var reportProcessor = new
    Telerik.Reporting.Processing.ReportProcessor();

               

                var instanceReportSource = new
    Telerik.Reporting.InstanceReportSource();

                instanceReportSource.ReportDocument
    = reportToExport;

               

               

                  

                if (type.ToLower().Equals("print"))

                {

                     //
    Obtain the settings of the default printer.

                    PrinterSettings printerSettings
    = new
    PrinterSettings();

     

                    //printerSettings.PrinterName
    = " HP Deskjet 3510 series";

                    //
    Print the report using the printer settings.

                   
    reportProcessor.PrintReport(reportToExport, printerSettings);

                }

                else

                {

                   
    Telerik.Reporting.Processing.RenderingResult result =
    reportProcessor.RenderReport(type,

                        instanceReportSource, null);

     

     

     

     

                    string fileName = "Viewr_" + cType + "_report." + result.Extension;

     

                    HttpContext.Current.Response.Clear();

                   
    HttpContext.Current.Response.ContentType = result.MimeType;

                   
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);

                    HttpContext.Current.Response.Expires
    = -1;

                   
    HttpContext.Current.Response.Buffer = true;

                   
    HttpContext.Current.Response.AddHeader("Content-Disposition",

                                     string.Format("{0};FileName=\"{1}\"",

                                                   "attachment",

                                                  
    fileName));

                   
    HttpContext.Current.Response.BinaryWrite(result.DocumentBytes);

                   
    HttpContext.Current.Response.End();

                }

              

              

     

                  

               

               

            }
  2. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 10 Oct 2014 Link to this post

    Hi Oguzhan,

    Below you can find a quote from my reply in your support ticket #867943 on the same question:

    In general, Reports are processed and rendered on the server. If the provided code snippet is executed on the server, the print operation will not happen on the client side. If the specified PrinterSettings are correct and sufficient to avoid popping any windows on the server, the report will be printed on the server.

    If you need to print the reports on the client, without displaying them, please test the approach described in the Print a report directly at client-side without displaying it in an ASP.NET ReportViewer code library post. The approach relies on exporting into PDF with injected Adobe PDF Javascript, that will force the used PDF reader to open its Print dialog automatically.



    If you need further help, please let us continue the discussion in your ticket, where we can freely exchange files.

    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.

     
Back to Top