How to make PDF file downloadable in HTML link

0 votes

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

<a href="myfile.pdf">Download Brochure</a>

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?

Aug 27, 2020 in PHP by kartik
• 37,520 points
19,896 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

<a href="./directory/yourfile.pdf" download="newfilename">Download the pdf</a>

Where newfilename is the suggested filename for the user to save the file. Or it will default to the filename on the serverside if you leave it empty, like this:

<a href="./directory/yourfile.pdf" download>Download the pdf</a>

Note:you should check  compatibility first.

Check compatibility here: http://caniuse.com/#feat=download

Hope it helps!!
Thank you!!

answered Aug 27, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How do I add PHP code/file to HTML(.html) files?

Hello @kartik, You can't run PHP in .html ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,840 points
669 views
0 votes
1 answer

How to include External CSS and JS file in Laravel?

Hello @kartik, The right way is this one: <script ...READ MORE

answered Oct 27, 2020 in PHP by Niroj
• 82,840 points
28,649 views
0 votes
1 answer

How to write file in UTF-8 format?

Hello @kartik, file_get_contents / file_put_contents will not magically ...READ MORE

answered Nov 5, 2020 in PHP by Niroj
• 82,840 points
6,065 views
0 votes
1 answer

How to check file extension in upload form in PHP?

Hello @kartik, Using if( $ext !== 'gif') might not ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,840 points
17,115 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
23,302 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
3,316 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
5,105 views
+1 vote
2 answers

How to set cache false for getJSON in jQuery?

You can't pass any configuration parameters to ...READ MORE

answered Oct 7, 2020 in JQuery by Amit
• 140 points
2,943 views
0 votes
1 answer

How do I convert a PDF document to a preview image in PHP?

Hello @kartik, You need ImageMagick and GhostScript <?php $im = new imagick('file.pdf[0]'); $im->setImageFormat('jpg'); header('Content-Type: image/jpeg'); echo ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,840 points
4,795 views
+1 vote
2 answers

How to make asynchronous HTTP requests in PHP?

Hello @kartik, Use this code: function post_without_wait($url, $params) { ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,840 points
2,647 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP