Show byte [] to your browser as .pdf (ASP.NET)


ReportingEngineService.PDFReportGenerator obj = new ReportingEngineService.PDFReportGenerator();
byte[] ByteArray = obj.GenerateWebReportInPDF(dsNM);
context.Response.Clear();
context.Response.Buffer = true;
context.Response.AddHeader(“Accept-Header”, ByteArray.Length.ToString());
context.Response.AddHeader(“Content-Length”, ByteArray.Length.ToString());
context.Response.AddHeader(“Content-Disposition”, “inline; filename=sample.pdf”);
context.Response.AddHeader(“Expires”, “0”);
context.Response.AddHeader(“Pragma”, “cache”);
context.Response.AddHeader(“Cache-Control”, “private”);
context.Response.ContentType = “application/pdf”;
context.Response.AddHeader(“Accept-Ranges”, “bytes”);
context.Response.BinaryWrite(ByteArray);
context.Response.Flush();
context.Response.End();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s