OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Force download a pdf on mobile device

  • Thread starter Thread starter Rubyx
  • Start date Start date
R

Rubyx

Guest
I want to force a pdf to be downloaded on mobile/tablet device to avoid open it in a new tab.

I tried with the download attribute:

Code:
<a href="file.pdf" download target="_blank">

It works on desktop but not on mobile.

I also tried with PHP header:

Code:
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: Binary');
header('Content-Disposition: attachment; filename="file.pdf"');
readfile('https://my-website.com/file.pdf');

But same, it works on desktop but not on mobile.

Any way to do this?
<p>I want to force a pdf to be downloaded on mobile/tablet device to avoid open it in a new tab.</p>
<p>I tried with the <code>download</code> attribute:</p>
<pre><code><a href="file.pdf" download target="_blank">
</code></pre>
<p>It works on desktop but not on mobile.</p>
<p>I also tried with PHP <code>header</code>:</p>
<pre><code>header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: Binary');
header('Content-Disposition: attachment; filename="file.pdf"');
readfile('https://my-website.com/file.pdf');
</code></pre>
<p>But same, it works on desktop but not on mobile.</p>
<p>Any way to do this?</p>
Continue reading...
 

Latest posts

Top