Output PDF Binary to Browser in ASP.NET

Output PDF Binary to Browser in ASP.NET

Here is the code to output PDF Binary to the browser using ASP.NET / VB.NET.

Note: This code assumes that you already have the PDF binary data stored in a byte() array called data.

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.BinaryWrite(buffer)
Response.End()

To add an Open / Save dialog window:

Response.AddHeader("content-disposition","attachment;filename=report.pdf")

If you encounter errors in Adobe Reader, make sure that your aspx page contains only the page directive:

<% @ Page Language="vb"%>

Related posts:

  1. A List of Coding Standard Websites
  2. ASP.NET – Access To Path is Denied
  3. How To Master a Programming Language IV
  4. What Programming Language Should I Learn Next?
  5. How to Read a Book Using SQ3R

Tags: , , , , , , ,

Leave a Reply