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"%>

  • Delicious
  • Share
  • Subscribe to RepeatGeek

Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to RepeatGeek

Subscribe via RSS

Enter your email address: