0

So here are the details:

Firefox: update 12
AdobeReader: 11
Input: Convert.FromBase64String(string)=> byte[]
Task: to display the pdf within the browser

PDF is stored in a database.

I've read and tried a lot of possible solutions and fixes for this error. But I got no joy.

Is it possible to know if the converted string to byte[] is corrupted? And is it possible for the value being converted to byte[] to be damaged in the process?

The value of the pdfFile, data type byte[], is from a web service.

Here is the generic handler that I made:

public partial class ProcessPDFRequest : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        try
            byte[] currentBillPDF = proxy.GetPdf(refNum, date);

            using (MemoryStream ms = new MemoryStream(currentBillPDF))
            {
                context.Response.Clear();
                context.Response.ContentType = "application/pdf";

                if(isInline!="true")
                    context.Response.AddHeader("content-disposition", "attachment;filename=PDF_CurrentBill.pdf");
                else
                    context.Response.AddHeader("content-disposition", "inline;filename=PDF_CurrentBill.pdf");
                context.Response.Buffer = true;
                ms.WriteTo(context.Response.OutputStream);
                context.Response.End(); ;
            }

EDIT

I use context.Response.Flush(); context.Response.End();

PDF was successfully displayed when I created another web application. However when I used the converted string to byte[] in the original solution, the error stated in the title is persisting. I already checked the bytes and compared it in notepad, both them showed %PDF-

Is there something I'm missing? the original solution is a sharepoint web application.

newbie
  • 3
  • 1
  • 8
  • (where is your actually code ) what about that answers ? http://stackoverflow.com/questions/18209505/pmedia-with-pdf-file-causes-file-does-not-begin-with-pdf-error-in-ie7 – Aristos Apr 17 '16 at 15:22
  • I've read those answers and tried them as well, but I got no luck. I also examined the returned byte[] and checked the PDF header, and there was no %PDF in the first 1024 bytes. I'm wondering if is it possible for the data to be converted in byte [] get damaged? – newbie Apr 17 '16 at 17:17
  • 1) Don't use `context.Response.End()` there. 2) If the data has come from a file, use [Response.TransmitFile](https://msdn.microsoft.com/en-us/library/12s31dhy%28v=vs.110%29.aspx) instead - it passes off the process to IIS and is more efficient. – Andrew Morton Apr 17 '16 at 18:49
  • ooh, this is noted. What if the data came from a database / web service? and it returned a series of strings then this strings were converted into byte[]... – newbie Apr 17 '16 at 19:12

0 Answers0