How to add a download="filename.pdf" attribute to a file link

franko1497
8 Posts
franko1497 posted this 09 September 2020
Ask a Question

Can anyone tell me if it is possible to add a download attribute to force a pdf to download rather than open in a browser window? I can't find anywhere to do this and I don't want the files opening in the browser as they don't display correctly.

Vote to pay developers attention to this features or issue.
4 Replies
Order By: Standard | Newest
Support Team
Support Team posted this 09 September 2020

Hi Frank,

There is no option to control that attribute and usually it depends on the user's browser how it will handle the PDF link.
You can only add the whole link manually with the code using the HTML control to add the desired attribute.

...................................................
Sincerely,
Hella
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

franko1497
8 Posts
franko1497 posted this 10 September 2020

Thanks for your response. Guess I'll have to manually code the element.

Support Team
Support Team posted this 10 September 2020

Hi Frank,

You are welcome. Feel free to contact us on any occasion.

...................................................
Sincerely,
Hella
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

peter.v.nagy
4 Posts
peter.v.nagy posted this 20 November 2024

I think it is somewhat easier to set the content disposition header of your web page. If your web page is hosted on an Apache web server, you can do it in a simple way. Let's say you would like any PDF file to be automatically downloaded from the web site instead of being displayed. Then, you have to create a file named '.htaccess', and write the following lines to the file:
<FilesMatch ".(pdf)$">

Header set Content-Disposition attachment

If you want more than one file type to be downloaded, then write this:
<FilesMatch ".(pdf|docx|zip)$">

Header set Content-Disposition attachment

If you want just a certain file to be downloaded, add the following lines to the .htaccess file:
<Files "example.pdf">

Header set Content-Disposition attachment

And upload the .htaccess file to the root directory, commonly the public_html folder, or any folder whose properties you want to modify.
Peter

You must log in or register to leave comments