'Download PDF file directly from external URL

I'm wondering if it's possible to download the PDF directly from another website's URL rather than opening a new window.

<a href="https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf" target="_blank"><button>Download FILE</button></a>


Solution 1:[1]

The most recommended way would be something like this enter image description here

<!DOCTYPE html>
<html>
<body>

<h3>https://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml5_a_download</h3>

<p>Click on the image to download PDF32000_2008.pdf<p>
<a href="https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf" download><img src="https://www.w3schools.com/images/myw3schoolsimage.jpg" alt="PDF32000_2008 standard" width="104" height="142">
</a>

<p><b>Note:</b> The download attribute is not supported in IE or Edge (prior version 18), or in Safari (prior version 10.1).</p>

</body>
</html>

That is preferable to your method in that it lets the user decide the time of the download and rename document! Also you only need to serve a cover icon or image. HOWEVER although this works without any problems for me as a client user "offweb" it may not work same as any other link on a server if it is cross site tainted. The href address should only be for resources served on or via your own site.

and that should also be the case even if you use iFrame or any other hyper download method, without addressing Cross Origin issues.

enter image description here

Hence something like your current method is often touted as a "workaround" to bypass any Cross Site limitation, since the call for a fresh tab is a direct link from client browser to remote source thus not via "person in the middle" again HOWEVER, you should improve security by adding to it:-

<a href="https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf" target="_blank" rel="noopener noreferrer"><button>Download FILE</button></a>

The linked page gains partial access to the linking page via the window.opener object:- see https://stackoverflow.com/a/45902400/10802527 and https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1