|
| iTextSharp - damaged document |
 |
Thu, 6 Mar 2008 17:15:45 +0000 |
So, created my pdf as required by my business logic, and after saving it to my
server i prompted the user to save it. This was successful, and now i tried
making all this work through a memory stream. First i placed the instance of the
document in the memStream
PdfWriter writer = PdfWriter.GetInstance(document, memStream);
Than, after adding my data did the following code:
MemoryStream ms = p.OpenPDFStream(filename); //custom
method which returns the above memStream
ms.Seek(0, SeekOrigin.Begin);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=" + filename);
Response.Buffer = true;
Response.Clear();
Response.OutputStream.Write(ms.ToArray(), 0,
ms.ToArray().Length);
Response.OutputStream.Flush();
Response.End();
p.Close();
This is of course prompting the usre to save the file, but once downloaded the
file can not be opened giving me the following error: 'There was an error
opening this document. The file is damaged and could not be repaired.' The same
file with the same data works if saved physically to the server. Any ideas?
Thanks!
|
| Post Reply
|
|
|
|
|
|
|
|
|
|