Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Mélanie Comtois
Mélanie Comtois
5,772 Points

How to download a pdf file (link) without viewing it.

How to download a PDF file (link) without viewing it I have a page with multiple pdf files to download. It is an html file for the moment (they wanted something very quickly) I will make this project in wordpress eventually. The client wants to click and have the download of the pdf files start directly, without viewing it in the browser. How can I do that. By default, the link gets open by pdf viewer.

Here is my code’s url : http://docs.solu-tex.com/

<a class="liens" target="_blank" href="documents/i01.1_SSI-EN_Intro-Products-and-Services.pdf">Download file</a>

PS I have no php yet, but I will

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You can try this, although I'm not sure how cross-browser compatible it is so you might have to test out that part. I tested it in Chrome on Windows 10.

Right now, you have your links set up to open in a separate tab by default. And the browser is then executing its default behavior which is to open the PDF.

<!-- This is what you have currently -->
<a class="liens" target="_blank" href="documents/i01.1_SSI-EN_Intro-Products-and-Services.pdf">Download file</a>

Try this:

<a class="liens" href="documents/i01.1_SSI-EN_Intro-Products-and-Services.pdf" download>Download file</a>

Note the removal of target="_blank" and the addition of download right before the >.

Hope this helps! :sparkles:

Mélanie Comtois
Mélanie Comtois
5,772 Points

So simple, it works , thanks