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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With