Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: force PDF download

Tags:

html

safari

I've a link to a PDF file in my page.

Safari opens the pdf file directly in the website. I would like to download it instead.

I've tried to add target="_blank" to <a> element, but it doesn't work if the pop-ups are disabled in the browser settings.

How can I solve this?

thanks

like image 926
aneuryzm Avatar asked Aug 29 '10 15:08

aneuryzm


People also ask

How do I force a browser to download PDF?

Click “Site Settings” on the right. Scroll down in Site Settings and click “Additional content settings” at the very bottom. In the expanded menu, select “PDF documents.” Toggle on the “Download PDF files instead of automatically opening them in Chrome” option.

How do I make a PDF downloadable in HTML?

Save / Save As optionCreate a link to download the file on the web page using the <A HREF> HTML tag. Then, recommend to the web page viewer that they right-click the link and choose the option to Save or Save as the file. Viewers can then download and save the file to their computer.

How do I trigger a download in HTML?

To trigger a file download on a button click we will use a custom function or HTML 5 download attribute. The download attribute simply uses an anchor tag to prepare the location of the file that needs to be downloaded.

How do I force a file to download from a website?

In most browsers, clicking on the link will open the file directly in the browser. But, if you add the download attribute to the link, it will tell the browser to download the file instead. The download attribute works in all modern browsers, including MS Edge, but not Internet Explorer.


1 Answers

To make so, you need to change headers for .PDF files.

So, in your .htaccess, you need to do like this:

AddType application/octet-stream .pdf
like image 152
shamittomar Avatar answered Jan 04 '23 15:01

shamittomar