Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android browser rejects content-disposition:inline?

Tags:

android

php

pdf

I am having trouble sending pdf files to an Android browser from a php script. Specifically, at http://aim.shef.ac.uk/misc/a.php I have the following script:

header('Content-Type: application/pdf');
header("Content-Disposition:inline;filename=\"c.pdf\"");
readfile('c.pdf');

This works as expected in a variety of desktop browsers, and also with an iPhone: the pdf file is displayed in the browser window, just as if I had browsed to http://aim.shef.ac.uk/misc/c.pdf directly. However, when I try it in an Android (2.3.3) phone, essentially nothing happens (despite the fact that the phone has several apps that can display pdf files). If I visit c.pdf directly, or if I change 'inline' to 'attachment' then the phone offers to save the file and then I can view it. This is less convenient, so I don't want to use 'attachment' for clients that can deal properly with 'inline'. I could just test $_SERVER['HTTP_USER_AGENT'] for the substring 'Android', and set the content disposition based on that. However, this seems kludgy and I do not know whether it is appropriate for all Android devices.

Any suggestions?

like image 225
Neil Strickland Avatar asked Mar 29 '12 13:03

Neil Strickland


1 Answers

Android phones can not render PDFs in the web browser. There is no support for that. Instead, you could use the google viewer. Have a look at https://docs.google.com/viewer for instructions.

like image 146
Alfred Godoy Avatar answered Oct 20 '22 09:10

Alfred Godoy