Skip to content
Advertisement

How to make PDF file downloadable in HTML link?

I am giving link of a pdf file on my web page for download, like below

JavaScript

The problem is when user clicks on this link then

  • If the user have installed Adobe Acrobat, then it opens the file in the same browser window in Adobe Reader.
  • If the Adobe Acrobat is not installed then it pop-up to the user for Downloading the file.

But I want it always pop-up to the user for download, irrespective of “Adobe acrobat” is installed or not.

Please tell me how i can do this?

Advertisement

Answer

Instead of linking to the .PDF file, instead do something like

JavaScript

which outputs a custom header, opens the PDF (binary safe) and prints the data to the user’s browser, then they can choose to save the PDF despite their browser settings. The pdf_server.php should look like this:

JavaScript

PS: and obviously run some sanity checks on the “file” variable to prevent people from stealing your files such as don’t accept file extensions, deny slashes, add .pdf to the value

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement