Copy link to clipboard
Copied
I've noticed that, with iOS and Android, if I click a link to a pdf on a web page, the file downloads, but is not recognized as a pdf and will only render as code, i.e:
%PDF-1.3 %verypdf.com 94 0 obj << /Linearized 1 /O 96 /H [ 249497 142 ] /L 355956 /E 249497 /N 5 /T 353957 >> endobj xref 94 61 0000000022 00000 n 0000249020 00000 n 0000249172 00000 n 0000249497 00000 n 0000249640 00000 n 0000249962 00000 n 0000250524 00000 n 0000251371 00000 n 0000252131 00000 n 0000252905 00000 n 0000253712 00000 n 0000254573 00000 n 0000255413 00000 n 0000256244 00000 n 0000256764 00000 n 0000256817 00000 n 0000257227 00000 n 0000257455 00000 n 0000257494 00000 n 0000260194 00000 n 0000260313 00000 n 0000260629 00000 n 0000260814 00000 n 0000264118 00000 n 0000264297 00000 n 0000264367 00000 n 0000264562 00000 n 0000269374 00000 n 0000269663 00000 n 0000269819 00000 n 0000269881 00000 n 0000270086 00000 n 0000281854 00000 n 0000282509 00000 n 0000282717 00000 n 0000292647 00000 n 0000293564 00000 n 0000293771 00000 n 0000305370 00000 n 0000305528 00000 n 0000305598 00000 n 0000305803 00000 n 0000319317 00000 n 0000319497 00000 n 0000319565 00000 n 0000319772 00000 n 0000329756 00000 n 0000330046 00000 n 0000330700 00000 n 0000330907 00000 n 0000341276 00000 n 0000342189 00000 n 0000342395 00000 n 0000352859 00000 n 0000352995 00000 n 0000353131 00000 n 0000353267 00000 n 0000353403 00000 n 0000353539 00000 n 0000353675 00000 n 0000353811 00000 n trailer << /Size 155 /Root 95 0 R /Info 98 0 R /Prev 353947 /ID[<56E4C8EF3FD5321647469877FEFBD0FA><3004995D1B548B7E3B23C9A9946D6BFF>] >> startxref 0 %%EOF 1 0 obj << /ProcSet [ /PDF /Text /ImageC ] /ExtGState << /GS1 113 0 R >> /Font << /F1 144 0 R /F2 141 0 R /F9 114 0 R /F5 129 0 R >> /Properties << /MC1 91 0 R >>
as so on. If I email the original pdf as an attachment and open the email on my device and download the attached pdf, my installed pdf viewer can then open it as expected.
Insight?
Thank you
Copy link to clipboard
Copied
Can you post the link of the web page?
Copy link to clipboard
Copied
In the process of setting up a link to test this, I realize that the issue has to do with our code. The original link in question is behind a login, so I can't expose that. But what I can say is that we're serving up the file in a PHP script, and I'm pretty sure the issue is with the headers we're using.
The current code is:
header('Content-Disposition: attachment; filename="' . $this->item->title . '.' . $extension . '"');
readfile($link);
I've found I can change the behavior by extending this thusly:
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . $this->item->title . '.' . $extension . '"');
readfile($link);
Which causes the expected download of the pdf, with obvious feedback in Android, but not in iOS.
Would "Content-Type: application/octet-stream" be more appropriate/effective? Something else? Also curious why this would not matter in a desktop browser, but would in a mobile browser.
And maybe this is really just a php question.
Copy link to clipboard
Copied
Use: application/pdf
Copy link to clipboard
Copied
A browser SHOULD use the Content-type to decide how to open the file. So it should be correct (application/pdf). However, some browsers, especially on desktop systems, have a fallback or overriding mechanism that uses the filename according to file association rules. This should not be relied upon. What would "download" mean for the iOS browser anyway? Doesn't seem to really have the concept, unless I've missed it. If it did download it, where would it go, and how would you access it?
Copy link to clipboard
Copied
My final solution, for reference:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename, etc.
Thanks for the feedback.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now