Click here to Skip to main content
16,019,593 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi to all,

I have many PDF documents in binary format, which is in the SQL Server 2008 database.
I have a gridview in my ASP.Net page.
When a user clicks on any ID column of the record I need to open the pdf in the browser.

Are there any free online PDF viewer controls out there?
How can I convert the binary PDF file and display as PDF in the browser using c#?

Regards,
Venki Desai.
Posted

1 solution

You don't need to convert it to a PDF, it already is. You just need to send the binary stream.

C#
private void SendDocument(byte[] buf)
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ContentType = "Application/pdf";

    HttpContext.Current.Response.AppendHeader("Content-Length", buf.Length.ToString());
    HttpContext.Current.Response.BinaryWrite(buf);

    HttpContext.Current.Response.End();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900