0

I have an ASP.Net WebForm that dynamically generates a pdf. The pdf download works in all the desktop browsers, as well as the IPad, Chrome mobile, and Firefox mobile. However, the pdf download fails in the Android browser with the message "Download Unsuccessful" in the notification area. I am writing the pdf to the response with this code:

using (PdfDocument pdf = this.RenderPDF())
using (MemoryStream stream = new MemoryStream())
{
    pdf.Save(stream, false);
    response.Clear();
    response.AddHeader("content-disposition", "inline;filename=myPdf.pdf");
    response.AddHeader("content-length", stream.Length.ToString());
    response.ContentType = "application/pdf";
    response.BinaryWrite(stream.ToArray());
    response.Flush();
    stream.Close();
    response.End();
}

What should I do differently to get the pdf download working in the Android browser?

1 Answers1

1

Since you said the PDF is generated by a form, I'm assuming that's in response to a POST. I'm having the same problem, and found this comment on a similar S/O question:

issue is due to a bug in the Android browser and Dolphin, which causes downloads to fail on POST actions. I changed my actions to GET as a workaround.

The issue referenced is Support download of POST responses - open since 2009!


(This question has several yet-unresolved iterations on S/O; neither closing nor answering them all seems reasonable, so how about some links:

Kimberly
  • 2,657
  • 2
  • 16
  • 24