tags:

views:

95

answers:

2

I has image into byte[]. I need to open it into adobe file in asp.net. I using following code :

byte[] bytes = contractimage.Value.Bytes;
                if (bytes == null)
                {
                    Response.Write("Not found.");
                    Response.End();
                }
                else
                {                    
                    Response.AddHeader("content-disposition",
                        "attachment;filename=statement" + contractGuid.ToString() + ".pdf");
                    Response.ContentType = "application/pdf";
                    Response.OutputStream.Write(bytes, 0, bytes.Length);
                    Response.End();
                }

But this code display an error that adobe canot dispalay this file it may be corrupted. Please suggest

A: 

You would have to format your output in the form of a PDF file, you are currently only sending the raw image data and not a properly formated PDF file.

You can refer to:

http://www.adobe.com/devnet/pdf/pdf_reference.html

for a specification of the PDF format or an easier solution is to use a third-party tool to accomplish your task.

Try a Google search for something like "pdf .net creator"

+1  A: 

A byte[] of a bitmap is not a pdf document.

What you need to do is create a pdf doc that contains your Bitmap. If I were in your shoes I would probably use something like ITextSharp to do that.

Tim Jarvis