Force Download PDF

I see different topics on forcing a PDF to download but none of the solutions work for me.

Here’s my problem:
I am using ACF Pro to capture a list of files within a WP page. Then I’m using Loopers to display the name of the documents, as well as link to the document using a button. However, I’d like to force download the PDF instead of it opening in the browser.

Here’s what I’ve tried:

  1. Use JS code, and put the button in the class “forcedownload”
    jQuery( document ).ready(function($) {
    $( “.forcedownload” ).attr( “download”, “” );
    });
  2. Use Custom Attributes to create an attribute “download” with value as the URL, in addition to the button’s URL parameter as the URL.
  3. #2, but with empty and placeholder values for attribute.
  4. #2, but with the URL field in Cornerstone as a placeholder or other random text

So far, the best result is #4, where I put “#” as the value in the URL parameter, and provide the actual URL to the attribute.
However, this downloads an empty PDF where special characters become “_”
For instance, https://something.com/media/files/something.pdf" as the URL downloads an empty file named “https___something.com_media_files_something.pdf” which obviously never existed.

Any suggestions on how to get this working?
BONUS: if I can hide the source URL from the user, even better!

It’s important to note that the file is on an external domain.
This article suggests that any of the above won’t work for external files.

Hey @thomasgeorge,

Thanks for reaching out!

You could try using the custom attribute to add the download option for your pdf, please check this thread.

Hope that helps.

Hi!
That’s the same as #2 I mentioned above. That does not work when the file is hosted on an external domain.

An alternative approach is showing an iFrame within my site that shows the PDF dynamically when the respective link is clicked. Any suggestions on how I can achieve that?

Hey @thomasgeorge,

Would you mind sharing the page URL so that we can check properly of your setup? It would also be best to give us access to your website. Please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Page URL where you added the pdf files

You can find the Secure Note button at the bottom of your posts.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.