Dynamic PDFs and Android default browser
I am working on delivering PDF files that are generated on demand to users of mobile devices. I am using ASP.NET MVC 2 and I generate the PDF using the Report Viewer local report export as PDF.
This gives me the raw byte[] of PDF content.
I then return it using:
return File( pdf , mimeType , "File开发者_运维技巧Name.pdf" );
Note, I have tried it with and without the "FileName.pdf" default name for saving the file.
It works great in desktop browsers and iPhones. I have tested with the WP 7 emulator and it seems like it would work if it could just read PDFs (it prompts for the proper file name to save it).
Android seems to be complaining, however.
I have tested on Droid-X and Droid devices and it always shows " Download unsuccessful" in the browser download results. On Opera Mini it prompted to save the file (when using the return method that included the file name) and the PDF opened fine after it was saved on the device.
I can return PDF files that already exist on disk just fine with: File( "~/filename.pdf" , "application/pdf" ); so it seems to just be a problem with dynamic PDFs.
Has anyone dealt with this issue before?
I have tested on Droid-X and Droid devices and it always shows " Download unsuccessful" in the browser download results.
AFAIK, that means either that the HTTP request failed or that the MIME type was not one for which there is an ACTION_VIEW
activity registered. Bear in mind that the DROID did not ship with a PDF viewer, and I forget if the DROID X did or not.
I agree with Chris, in that it feels like the problem is an invalid MIME type. Consider using curl
or a browser plugin to inspect your HTTP response headers and confirm that, indeed, application/pdf
is being returned as the MIME type.
If that does not help, and you can supply us with a URL to test, that would help as well.
I see this questions id from years ago, but if you just want to display the pdf, you can embed your pdf URL in google doc viewer, and then reference that URL, then it should open on android browsers.
However, this will only work if your URL is publicly accessible.
精彩评论