I'm doing a series of reports which I need to generate the PDF and save to the server for the user to download. I can not use atatchment
mode and inline
mode. Because the user has the option to create multiple reports and download later.
Follow the conversion section:
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>21cm</PageWidth>" +
" <PageHeight>29.7cm</PageHeight>" +
" <MarginTop>0.1in</MarginTop>" +
" <MarginLeft>0in</MarginLeft>" +
" <MarginRight>0in</MarginRight>" +
" <MarginBottom>0.1in</MarginBottom>" +
"</DeviceInfo>";
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
// HttpContext.Current.Response.AddHeader("content-disposition", "C:\ExportedReport." + "PDF");
HttpContext.Current.Response.AddHeader("content-disposition", ("atatchment; filename=ExportedReport." + "PDF"));
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();