18 Answers, 1 is accepted
You can use the following code snippet to programmatically export the report into "PDF" format from a Web Site or Web Application project:
void ExportToPDF(string reportName, Telerik.Reporting.Report reportToExport) |
{ |
string mimeType = string.Empty; |
string ext = string.Empty; |
Encoding encoding = Encoding.Default; |
byte[] reportBytes = Telerik.Reporting.Processing.ReportProcessor.Render( |
"PDF" |
, reportToExport |
, null |
, out mimeType |
, out ext |
, out encoding); |
string fileName = reportName + ".pdf"; |
Response.Clear(); |
Response.ContentType = mimeType; |
Response.Cache.SetCacheability(HttpCacheability.Private); |
Response.Expires = -1; |
Response.Buffer = false; |
Response.AddHeader("Content-Disposition", |
string.Format("{0};FileName=\"{1}\"", |
"attachment", |
fileName)); |
Response.OutputStream.Write(reportBytes, 0, reportBytes.Length); |
Response.End(); |
} |
For the Web Site you may need to manually specify the folder in which the "PDF" rendering extension is located using this code line:
Telerik.Reporting.Processing.ReportProcessor.ExtensionDir = HttpContext.Current.Server.MapPath("~/bin");
Also, make sure that Telerik.Reporting.ImageRendering.dll resides in the Bin folder of the application.
Best wishes,
Chavdar
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thnx already,
Kevin
I have a page where you can select some options, this I forward in a querystring to another page where I request this querystring. On that page I request data from my database with those variables. And after that I bind it to the report. And with the script bellow you can't send variables :(
Any ideas mate?
here is my code in the page load event. there are no controls on this page what so ever.
ReportLib.Plumbworld.rptDeliveryNotices.PassDeliveryDate = Session["DeliveryDate"].ToString();
ReportLib.Plumbworld.rptDeliveryNotices rpt = new ReportLib.Plumbworld.rptDeliveryNotices();
ExportToPDF("Deliveries", rpt);
ReportLib.Plumbworld.rptDeliveryNotices.PassDeliveryDate = Session["DeliveryDate"].ToString();
I work like this, the code I show is on the page load of my reportviewer:
//here I request my data
VerhuurGeschDA verhuurGeschDA = new VerhuurGeschDA();
VerhuurGeschData data = verhuurGeschDA.GetDataNietBetaald("Kevin", Request.Querystring["var1"].ToString());
//here I attach my data to my reportviewer
ReportViewer1.Report = (Telerik.Reporting.Report)new VerhuurRapport();
ReportViewer1.Report.DataSource = data;
I try the code given by Chavdar on 14tyh June... and I get this message :
"sys.webforms.pagerequestmanagerparsererrorexception the message received from the server could not be parsed ... ... ... "
I think it is due to the fact that the linkbutton event where I call the method is not making a regular PostBack because this linkbutton is linked to a RadAjaxManager Prometheus....
Do you have any idea to help me ?
Thank for your help,
//here I request my data
VerhuurGeschDA verhuurGeschDA = new VerhuurGeschDA();
VerhuurGeschData data = verhuurGeschDA.GetDataNietBetaald("Kevin", Request.Querystring["var1"].ToString());
//here I attach my data to my reportviewer
VerhuurRapport myReport = new VerhuurRapport();
//the export to pdf dont need report viewer
ExportPDF("YourReport",myReport)
You are right that the ajaxification of the LinkButton is causing the trouble. The browser's build-in XmlHttpRequest object doesn't interpret correctly the content type of the response and there is nothing we can do to fix this behavior. Given this you have the following choices:
- To remove the LinkButton from the ajaxified controls list and allow it do regular postbacks
- To use Respose.Redirect in the Click event handler and redirect to a page that can serve the report:
protected void LinkButton1_Click1(object sender, EventArgs e)
{
Response.Redirect("ExportReport.aspx");
}
and in the Page_Load event of the ExportReport.aspx have something like this:
protected void Page_Load(object sender, EventArgs e)
{
this.ExportToPDF("Report1", new Report1());
}
- Use javascript code to manually make a new request to the report page.
For your convenience I have attached several sample pages which show the approached mentioned above. Let me know if you have any other questions.
Regards,
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
i need to export to pdf in landscape format. please suggest me on this requirement.
Thanks in Advance
i need to generate PDF in landscape format. any suggestion on this requirement will be a great help.
Thanks in advance
All you need to do is to set the Report.PageSettings to the desired page orientation like this:
myReport.PageSettings.Landscape = True |
where myReport is Telerik.Reporting.Report class instance.
All the best,
Svetoslav
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thanks. It is working.