Its not a code problem. Use Foxit Reader and it will open it. pdf's created in a much older version of Adobe's creator software cannot be opened by 9.x and version 10 in some scenarios. This problem occurs on Windows 7 Pro and Windows XP SP 3.
I don't think the error is in your code for downloading the document. I believe the error is happening because of how the document is originally stored in the database. Make sure you aren't using the GetBuffer() method when writing the file to the database.
Try using ToArray() instead and it will not append extra characters to the end of your file stream. Here's a link to give you some more details:
http://msdn.microsoft.com/en-us/library/system.io.memorystream.getbuffer.aspx
The extra characters after the %%EOF tag at the end of your PDF document are most likely what is causing the message:
“There was an error opening this document. The file is damaged and could not be repaired.”
Try opening your document in VIM/SlickEdit, etc (something that shows hidden characters) to verify that extra data is getting tacked onto the end of the file (it will just look like a bunch of spaces in notepad). You can also confirm this by checking the
size of the document vs. the size of the data stored in your database field.
This is an old post, but it helped me solve my similar problem, so I'm adding my findings to this post in the hopes that it helps someone else.
I encountered this problem as well. Jason's tip to open the document in a text editor helped me get to the bottom of my problem, along with Glade's mentioning of extra characters after the %%EOF. The problem was extra characters after the EOF that were
getting added after my document was being displayed.
Looking at maniac's code, I see the same issue in his code that was causing the problem in my code. There was a Response.End() that both maniac and I had commented out because it was giving a Threading.ThreadAbortException. That Response.End() is required,
or else extra content will be appended to the bottom of the PDF file, causing it to be corrupted on retrieval from the database.
As a side-note, I had tried replacing my Response.End() with a HttpContext.Current.ApplicationInstance.CompleteRequest(), but that was not sufficient to avoid appending the extra content to the PDF.
jasonmichael...
Member
9 Points
2 Posts
Re: “There was an error opening this document. The file is damaged and could not be repaired.”
Jan 03, 2011 09:26 PM|LINK
Its not a code problem. Use Foxit Reader and it will open it. pdf's created in a much older version of Adobe's creator software cannot be opened by 9.x and version 10 in some scenarios. This problem occurs on Windows 7 Pro and Windows XP SP 3.
Glade Mellor
Member
6 Points
4 Posts
Re: “There was an error opening this document. The file is damaged and could not be repaired.”
Mar 09, 2011 06:42 PM|LINK
I don't think the error is in your code for downloading the document. I believe the error is happening because of how the document is originally stored in the database. Make sure you aren't using the GetBuffer() method when writing the file to the database. Try using ToArray() instead and it will not append extra characters to the end of your file stream. Here's a link to give you some more details: http://msdn.microsoft.com/en-us/library/system.io.memorystream.getbuffer.aspx
The extra characters after the %%EOF tag at the end of your PDF document are most likely what is causing the message:
“There was an error opening this document. The file is damaged and could not be repaired.”
Try opening your document in VIM/SlickEdit, etc (something that shows hidden characters) to verify that extra data is getting tacked onto the end of the file (it will just look like a bunch of spaces in notepad). You can also confirm this by checking the size of the document vs. the size of the data stored in your database field.
I hope this helps.
Glade Mellor
PDFs memorystream
jozolo
Member
2 Points
1 Post
Re: “There was an error opening this document. The file is damaged and could not be repaired.”
May 04, 2012 01:00 PM|LINK
This is an old post, but it helped me solve my similar problem, so I'm adding my findings to this post in the hopes that it helps someone else.
I encountered this problem as well. Jason's tip to open the document in a text editor helped me get to the bottom of my problem, along with Glade's mentioning of extra characters after the %%EOF. The problem was extra characters after the EOF that were getting added after my document was being displayed.
Looking at maniac's code, I see the same issue in his code that was causing the problem in my code. There was a Response.End() that both maniac and I had commented out because it was giving a Threading.ThreadAbortException. That Response.End() is required, or else extra content will be appended to the bottom of the PDF file, causing it to be corrupted on retrieval from the database.
As a side-note, I had tried replacing my Response.End() with a HttpContext.Current.ApplicationInstance.CompleteRequest(), but that was not sufficient to avoid appending the extra content to the PDF.