Share via


Open PDF file from Byte array

Question

Monday, April 16, 2012 11:38 AM

Hello,

  In my application, the users can upload their documents and they should be able to view the uploaded documents. When the documents are uploaded, I am converting them in to byte array and saving them in database. Now, the problem is,

1) How do i open a pdf file from the byte array. What would be the best way to do this?

2) The users can upload any format of the document, say .jpg,.png,.pdf etc. But, when I am retrieving the doc from database, I would like to show all the documents as  a pdf file. 

Appreciate the help

Thanks

All replies (3)

Monday, April 16, 2012 1:55 PM âś…Answered

Refer this

http://forums.asp.net/t/1263188.aspx

http://pubudini.blogspot.in/2010/02/cnet-how-to-convert-pdf-document-to.html


Monday, April 16, 2012 1:56 PM

refer:

http://www.codeproject.com/Questions/100792/How-to-convert-a-byte-array-to-a-pdf

http://www.codeproject.com/Questions/203627/Convert-a-byte-array-to-pdf-in-c


Monday, April 16, 2012 2:43 PM

I used the following code to open a pdf file. But i have one more problem.

Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline;filename=data.pdf");
Response.BufferOutput = true;
byte[] pdf;
Response.AddHeader("Content-Length", response.Length.ToString());
Response.BinaryWrite(pdf);
Response.End();
The user can also upload .jpg,.png etc. I am converting them to byte array before saving.
Those byte arrays are not opening with the code above.  Do i have to change the contentType?
How can i do that?