I have a byte array and now I want to convert the byte array to a pdf file. I am using the following code, but when I try to see/open the pdf file, it shows
"Adobe reader could not open 'sample.pdf' becauase it is either not a supported file type or because the fiel has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)"
my code that i am using to byte[] to pdf convert.
pdfByte is a byte array.
MemoryStream m = new MemoryStream(pdfByte);
Response.Clear();
Response.AddHeader("Content-Length", pdfByte.Length.ToString());
Response.ContentType = "application/pdf";
Response.AddHeader("Expires", "0");
Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
Response.AddHeader("Pragma", "public");
Response.AddHeader("Content-Disposition", "attachment; filename=sample.pdf");
Response.BinaryWrite(pdfByte);
Response.Flush();
Response.End();
I have also tried with the following code:
Response.Clear();
MemoryStream ms = new MemoryStream(pdfByte);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
but in both case, I see the above message when I try to open the pdf file that just created. so,need to find out the issue why this happens? Please help.
Thanks, Arefin
Thanks,
Arefin