I have a web api controller that is returning PDF. Some PDFs are not being opened by Abobe Reader XI 11.0.12
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.BinaryWrite(myByteArray);
HttpContext.Current.Response.End();
The above code works without errors, and PDFs can be opened in Adobe Reader as well in all popular browsers.
But it does throw "Server cannot set status after HTTP headers have been sent." which I have been ignoring but would like to resolve, so I implement the below code.
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.BinaryWrite(myByteArray);
HttpContext.Current.Response.Flush();
This code also works without errors, but the PDF returned from this code cannot be opened in Adobe Reader XI version 11.0.12. FF, Chrome, Edge can show the PDF fine. IE 11 cannot.
There was an error opening this document. The file is damaged and could not be repaired.