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

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

1 Answer 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Oguzhan
Top achievements
Rank 1
Oguzhan asked on 10 Oct 2014, 09:35 AM
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();

            }

          

          

 

              

           

           

        }

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 10 Oct 2014, 04:41 PM
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.

 
Tags
General Discussions
Asked by
Oguzhan
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or