Copy link to clipboard
Copied
I'm developing a vb.net web application. Recently I face a problem where the PDF file with version 1.5 and higher are not able to view/download through browser. When I click the link to view the PDF file, the browser will prompt a "File Download" message box, when I choose to open the PDF file, the adobe reader display this error "There was an error opening this document. The file is damaged and could not be repaired." Even if I choose "Save" to PC then open the PDF file, it still display the same error message.
Please note that the sources for those PDF file is from scanner. If I'm using the Microsoft Word to save the document as PDF, it has no issue in viewing the PDF file no matter in what PDF version.
The code I'm using for view attachment is as below:
HTTPContext.Current.Response.ContentType = "APPLICATION/PDF"
HTTPContext.Current.Response.AppendHeader("Content-Disposition", "Attachment; Filename=XXX.pdf")
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.WriteFile(System.IO.FileInfo(FILE_PATH).FullName)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Is there any issue with the code? Any solution to resolve this issue?
Copy link to clipboard
Copied
Can you open the file in Adobe Acrobat?
Copy link to clipboard
Copied
Yes, it can be opened as normal. But when I use the web application to view/download the PDF file, it cannot be opened.
Copy link to clipboard
Copied
Compare the file which the app received with the file on the server.
Copy link to clipboard
Copied
When I compare the PDF download from the application with the original file on server, the only different is the downloaded PDF file has some HTML embedded code after the original content.
Copy link to clipboard
Copied
This may be the reason for the error message.
Copy link to clipboard
Copied
So why some of the PDF file will included the HTML embedded code?
Copy link to clipboard
Copied
The web-server script that is serving it is doing a bad job of it...
Copy link to clipboard
Copied
Sounds like an issue with your browser's PDF plugin...
Copy link to clipboard
Copied
At first, I also guess whether is this issue, but when I try to scan the PDF again and try to view through the web application, it works. The PDF version I re-scan is 1.6.
Copy link to clipboard
Copied
Not sure is there away for me to upload the PDF file in this forum for checking?