This is a common issue but few people know there's a simple HTML 5 solution:

<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>

Compatibility: I tested this on Firefox 21 and Iron, both worked fine. It might not work on HTML5-incompatible or outdated browsers. The only browser I tested that didn't force download is IE...

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

Answer from T_D on Stack Overflow
Top answer
1 of 14
264

This is a common issue but few people know there's a simple HTML 5 solution:

<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>

Compatibility: I tested this on Firefox 21 and Iron, both worked fine. It might not work on HTML5-incompatible or outdated browsers. The only browser I tested that didn't force download is IE...

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

2 of 14
121

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

<a href="pdf_server.php?file=pdffilename">Download my eBook</a>

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:

header("Content-Type: application/octet-stream");

$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp); 

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

🌐
Reddit
reddit.com › r/html › how do i allow someone to download a pdf file
r/HTML on Reddit: How do I allow someone to download a pdf file
January 26, 2025 -

I'm making a small little website for a game I'm making in uni (it's literally only 3 pages) and I want the user to download a pdf file of a "cheat sheet" of the game (right now I'm just using a text file but I'm hoping that the file type can easily be changed) and I haven't got the faintest idea on how to do that

I have next to no knowledge on html aside from a college course I did 3 years ago and this was never even apart of it so any help will be MASSIVELY appreciated

Discussions

Download chrome HTML instead of PDF?
It sounds like you're using either Ctrl+S or the "Save As" on a web page, and not an actual PDF. A screenshot of the page (unless it contains confidential or otherwise private information and you do not know how to blurry/black those out) would probably help people identify what you should be doing. But my guess is that you should look for a download/open/save button from within the page itself, and not the browser UI. It is also possible that they do not want you to download the content, and have it as images in an html web page instead of a pdf; in which case you might be able to get the images individually, though it can be more or less complex depending on how the page is set up. More on reddit.com
🌐 r/Windows11
5
0
November 11, 2022
Anyone know a good HTML to PDF converter?
Hello u/Kategorisch ! Thank you for posting in r/DataHoarder . Please remember to read our Rules and Wiki . Please note that your post will be removed if you just post a box/speed/server post. Please give background information on your server pictures. This subreddit will NOT help you find or exchange that Movie/TV show/Nuclear Launch Manual, visit r/DHExchange instead. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/DataHoarder
17
3
December 8, 2022
Introducing package: The HTML to PDF Converter!
Wouldn't you lose all the text with this method? It would be just one large image inside a PDF. At that point, the PDF loses a lot of its usability. More on reddit.com
🌐 r/webdev
23
27
December 3, 2023
Converting HTML book to PDF
Hi, I have two folders, one with html and css files, the other with images. I can browse the html book on a web browser but I'd like to do a search… More on reddit.com
🌐 r/HTML
3
2
November 16, 2023
🌐
PDFCrowd
pdfcrowd.com › html-to-pdf
Convert HTML to PDF Online - PDFCrowd
Convert HTML files and web pages to PDF with the Pdfcrowd HTML to PDF online tool.
🌐
Sejda PDF
sejda.com › html-to-pdf
Convert HTML to PDF Online
Click Convert HTML to PDF and wait until processing completes. Then press Download and save your PDF documents.
🌐
W3Schools
w3schools.com › tags › att_a_download.asp
HTML a download Attribute
The optional value of the download attribute will be the new name of the file after it is downloaded. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).
🌐
iLovePDF
ilovepdf.com › html-to-pdf
HTML to PDF converter. Transform HTML pages into PDF
Convert HTML pages to PDF documents for free with our HTML to PDF converter. Transform any web page to a PDF document. Easy, fast and without registration.
Find elsewhere
🌐
CloudConvert
cloudconvert.com › html-to-pdf
HTML to PDF | CloudConvert
>HTML to PDF Converter - CloudConvert is a free & fast online file conversion service.
🌐
wkhtmltopdf
wkhtmltopdf.org
wkhtmltopdf
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service. There is also a C library, if you're into that kind of thing. Download a precompiled binary or build from source
🌐
PDFmyURL
pdfmyurl.com
Convert Any URL, Web Page or Website to PDF – Online & API | PDFmyURL
Convert web pages, entire websites or raw HTML to high-quality PDFs using our online tool or HTML to PDF API. No software required. Trusted since 2008 by thousands of customers.
🌐
Stanford
web.stanford.edu › group › csp › cs21 › htmlcheatsheet.pdf pdf
HTML Cheatsheet page 1 of 2 Basic Tags
Creates an HTML document · Sets off the title & other info that isn't displayed
🌐
Adobe
adobe.com › acrobat › resources › how-to-convert-html-to-pdf.html
How to convert HTML to PDF | Adobe Acrobat
1. Open Acrobat and choose Tools › Create PDF › Web Page. 2. Enter the complete path to the web page, or click Browse and locate an HTML file. 3. Click Capture Multiple Levels and enter the number of levels to include.
🌐
Prince
princexml.com
Prince - Convert HTML to PDF with CSS
It’s quick and simple to convert HTML to PDF with Prince. HTML is seamlessly transformed into documents you can print, download and archive.
🌐
Digitalocean
assets.digitalocean.com › books › how-to-build-a-website-with-html.pdf pdf
How To Add a Background Image to the Top Section of Your Webpage With HTML
HTML · : ULWWHQE\(ULQ*ODVV · ,Q · WKLV · WXWRULDO · ZH OO · OHDUQ · KRZ · WR · XVH · DGLY! FRQWDLQHU · WR · VWUXFW · WK · WRS · VHFWLRQ ·
🌐
FreeConvert
freeconvert.com › html-to-pdf
HTML to PDF | Free Online HTML to PDF Converter
Click the "Choose Files" or "Enter ... the "Download PDF" button · Simply upload your HTML files or enter webpage URLs and then hit the “Convert” button to start converting to PDF format....
🌐
Webdesign
webdesign.org › downloads › Beginners_Guide_to_HTML.pdf pdf
Beginner's Guide to HTML
This is another good news: when you are learning HTML, you do not need much. You can start with using Notepad, a text editor that is included in your Windows · installation. If you are not using Windows, or if you prefer other text editors, there is a · lot of free software that you can download ...
🌐
Chrome Web Store
chromewebstore.google.com › detail › ljbonnllckbdpfpjncfaoiakjjgjfmde
HTML to PDF - Chrome Web Store
Use HTML file to PDF: convert HTML to PDF in one click. Save webpage as PDF easily, preserving layout for offline access. ... Average rating 3.4 out of 5 stars. Learn more about results and reviews. Install webpage to PDF converter & capture entire webpage as pdf. Or edit PDF and download with one click.
🌐
Go Make Things
gomakethings.com › how-to-force-a-file-to-download-instead-of-open-in-the-browser-using-only-html
How to force a file to download instead of open in the browser using only HTML | Go Make Things
February 24, 2020 - But, if you add the download attribute to the link, it will tell the browser to download the file instead. <a href="/path/to/your/receipt.pdf" download>Download Receipt</a>