0

Currently, I am sending a link within an email which points to a downloadable PDF file:

<a 
style="cursor:pointer;
href="'.get_site_url().'/wp-content/generated-pdfs/topplaatje-'.$post_id.'-'.$count.'.pdf"
download>PDF Print '.$count.'</a>

Unfortunately, when users click this link in their email client, they're taken to their browser where the PDF displays. I want it to download directly, instead of opening in browser.

I added the download tag to the <a href, but to no avail. Any ideas?

  • Does the answer about the headers work for you? https://stackoverflow.com/a/6794317/8942566 – Nathan Jan 11 '21 at 22:06

1 Answers1

0

Here's an answer suggesting the use of the download attribute on your link if you must have a direct download.

<a href=".../myFile.PDF" download="my-suggested-file-name">Click to download</a>
D M
  • 5,769
  • 4
  • 12
  • 27
  • Tried, and failed. – Kevsterino Jan 11 '21 at 16:07
  • Is there a reason the PDF viewer's download button is not good enough? If so, you will need to be able to set headers on the HTTP Response from the server when the user attempts to access the file. Set the ```Content-Disposition``` header to ```attachment``` to have the browser treat the file as a download. [Example](https://www.codeproject.com/Articles/15649/Create-and-download-text-file-from-a-web-page) – D M Jan 11 '21 at 16:21
  • The reason the viewer button isn't good enough, is due to the fact that these files will be sent to a printer. By the hundreds. We're trying to make everything as simple as possible for them, because, well, they are simple. Attaching them within mail isn't a possibility either due to the large file size. – Kevsterino Jan 12 '21 at 07:19
  • Ahh, I see. If they have to be delivered via a link in an email, then I think my comment above applies. You’ll have to change the server configuration. – D M Jan 12 '21 at 13:49